Frank Q.
Frank Q.

Reputation: 6592

Extracting substring Regex

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 ?

Upvotes: 0

Views: 25

Answers (1)

Eser
Eser

Reputation: 12546

You can do it as:

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

Upvotes: 1

Related Questions