Regular Expressions Greedy & Non-greedy Selection; regex
If your regex pattern is too greedy, that is, it finds the largest matching case when you want it to find the smallest matching pattern, use a non-greedy selection.
Replace the greedy quantifier with the corresponding non-greedy version.
"...change * , + , ? , and {} into *? , +? , ?? , and {}? , respectively"
from | to |
---|---|
* | *? |
+ | +? |
? | ?? |
{} | {}? |
More from the Perl Cookbook http://docstore.mik.ua/orelly/perl/cookbook/ch06_16.htm
Comments
Leave a Reply