The * modifier in regular expressions is "greedy". That means it will match the most that it possibly can. You can get a non-greedy match by adding ? after it like so:
m/name="challenge" value="(.*?)"/
Note that in general this won't cope with escaped quotes as in "* is \"greedy\" in regex". Before there were non-greedy matches, I might have written the expression this way (which also doesn't cope with escaped quotes):
m/name="challenge" value="([^"]*)"/
Or, given your input, this way (which will only match a hexadecimal string):
m/name="challenge" value="([0-9a-f]+)"/
As an aside, let me recommend in general using something like HTML::Parser when you're parsing HTML. Getting it right with regular expressions can be really difficult, but the module does the right thing for you.
In reply to Re: Regexp question
by kyle
in thread Regexp question
by davidov0009
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |