Jump to content

Regex problem for using an OR statement


fapapfap

Recommended Posts

The following regex looks for the pattern including </a>.  I would like to add in an OR condition which also includes patterns which include </span>, which somestimes is shown in results in place of </a>, is that possible?

 

 

Regex:

 

$pattern = '~">[^ ]+<\/a>~i';

 

I thought I could do '~">[^ ]+(<\/a>|<\/span>)~i';

 

But doesn't work

Link to comment
https://forums.phpfreaks.com/topic/253953-regex-problem-for-using-an-or-statement/
Share on other sites

What about:

 

$pattern = '/(<\/a>)|(<\/span>)/';

 

Hi thanks for replying but it is slighly more complex because of the full search string:

 

$pattern = '~\<a href="http:\/\/www\.site\.net\/page\.php\?action=p\&uid=[0-9]+">[^ ]+<\/a>~i';

 

 

This will successfully extract the TEXT in the following HTML:

 

<a href="http://www.site.net/page.php?action=p&uid=29">TEXT</a>

 

But not instances where the format changes slightly:

 

<a href="http://www.site.net/page.php?action=p&uid=29"><span style="color:#ffcc00">TEXT</span></a>

 

An adjustment to the pattern regex is what I am looking for so to still extract the TEXT given either of these formats

 

(NOTE: THE COLOUR HEX IS VARIABLE!)

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.