Dennis Hackethal
Dennis Hackethal

Reputation: 14295

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 (.+?) ?

Upvotes: 0

Views: 789

Answers (1)

Pascal MARTIN
Pascal MARTIN

Reputation: 401182

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 .

Upvotes: 1

Related Questions