I have a sentence:
“This ‘is’ just an example”
I need to cut the word between first ‘ ‘ characters.
Up until now, I was using following Regex method:
string name_only = Regex.Match("This 'is' just an example", @"\'([^)]*)\'").Groups[1].Value;
Result: is
and it worked perfectly fine, until another ‘ appeared:
“This ‘is’ just an e’xample”
now I’m getting:
Result: is’ just an e
how do I fix this issue (other than iterating using the “for” cycle and finding first two inexes of character ‘ and then cutting the word using the substring) ?
The problem is that your regex acts in a greedy way and if you change it to the following it will work: