0

I have the following string

[function('lookup')]

I want to extract the string lookup from the string above.

Tried doing using

var lookup = Regex.Match("[function('lookup')]", @"'\b\w*\b'").Value;

I end up getting 'lookup' with the single quotes instead of just lookup.

Where am I going wrong ?

3
  • Well yes, your pattern includes the quotes. Why would you expect it not to include the quotes? You could either just strip them off the front and back, or put a capturing group inside the quotes. Commented May 20, 2016 at 21:44
  • If I remove the quotes I end up with function. Is there a better way to directly extract out lookup ? Commented May 20, 2016 at 21:46
  • No, I mean remove the quotes from the result. But yes, you could use a capturing group... Commented May 20, 2016 at 21:57

1 Answer 1

1

You can do it as:

var lookup = Regex.Match("[function('lookup')]", @"'\b(\w*)\b'").Groups[1].Value;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.