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
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!)

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.