Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catch everything between two same words multiple times

i have this huge text, and i would like to catch everything between the words "Empresa". I'm trying to, but the second regex is being ignored, and i can't figure it out why:

/(Empresa.*?Empresa)/

http://regexr.com/3cm8a

The problem is, i can catch Empresa - EVERYTHING - Empresa.. But the next, is being ignored, because is being used by the previous regex.

So, i would like to improve to catch at all, but i can't figure it out how.

Thanks!!!


1 Answers

Use the /g modifier for the regexp to match multiple times.

Then .match() will return a list you can iterate over.

like image 141
neuhaus Avatar answered Jul 07 '26 11:07

neuhaus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!