I am having trouble trying to write a non-greedy regex statement.
Here is my string:
<strong>name</strong><strong>address</strong>mailto:[email protected]
Here is my regex query:
<strong>(.*?)</strong>.*?([A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4})
The problem is that I need the the address, not the name from the string. So I need the regex query to be non-greedy and take the closest <strong></strong> instead of the farthest away.
There are also multiple instances of this in my search string, so it would have to match multiple instances at a time instead of just adding a .* (greedy) thing in front of it.
So it would have to match all the instances of this, and pull the addresses, not names:
<strong>name</strong><strong>address1</strong>mailto:[email protected]
<strong>name</strong><strong>address2</strong>mailto:[email protected]
<strong>name</strong><strong>address3</strong>mailto:[email protected]
<strong>name</strong><strong>address4</strong>mailto:[email protected]
Thanks in advance!
$to the end of your regex is what you're looking for?)<strong>/</strong>pair to match as far to the right as possible before the mail address. But that's not how non-greedy matches work. For a quick-and-dirty solution, I'd just use[^<]*instead of.*?-- since<is illegal in HTML except to start a tag, that will match any legal content of the address field, but keep it from matching the tags.