I need a help with regular expression as I do not have good knowledge in it.
I have regular expression as:
Regex myregex = new Regex("testValue=\"(.+?)\"");
What does (.+?) indicate?
The string it matches is "testValue=123e4567" and returns 123e4567 as output.
Now I need help in regular expression to match a string "<helpMe>123e4567</helpMe>" where I need 123e4567 as output. How do I write a regular expression for it?
This means:
In the case of your regex, the non-greedy quantifier
?means that your captured group will begin after the first double-quote, and then end immediately before the very next double-quote it encounters. If it were greedy (without the?), the group would extend to the very last double-quote it encounters on that line (i.e., “greedily” consuming as much of the line as possible).For your “helpMe” example, you’d want this regex:
Given this string:
You’d get this match:
The value of the non-greedy quantifier is evident in this variation:
The greedy capture would look like this:
There are some useful interactive tools to play with these variations: