regex - Perl - regular expressions first occurrence of group -


i matching line against pattern, like:

 if (/.*someregexp(.*)someotherregexp.*/) { process $1 }  

but, problem have, in line, many occurrences of "someregexp(.*)someotherregexp"

can please tell me how can select, sure!, first occurrence?

thank you!

you need make quantifiers not greedy. * greedy default, means tries capture as possible. make not greedy, add ?:

if (/.*?someregexp(.*?)someotherregexp.*?/) {     process $1 } 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -