Skip to content
Advertisement

Regexp ignore certain parts in string

I need to use regex for a string to find matching results. I need to find the (.+?) but would like to ignore everything where it says (*) right now:

$regex='#<span class="(*)"><a href="/venues/(*)">(.+?)</a></span>#';

Instead of ignoring (* ), it echoes out what is in (* ).

How can I ignore these and only get (.+?) ?

Advertisement

Answer

The parenthesizes mean capture: what’s inside those () will be captured so you can use it later.

If you do not want something to be captured, because you don’t want/need to use it later, just remove the parenthesizes.

I should add that using regular expressions to extract data from HTML is generally quite not such a good idea… You might want to use a DOM parser instead, with DOMDocument::loadHTML() for example .

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement