Jump to content

Need an example


tejama

Recommended Posts

I need an example of a regex that will find the name 'Ortiz' and parse it so that it returns on the last number on this line (which is 16).

 

Ortiz</a></td><td>90</td><td>330</td><td>61</td><td>106</td><td>32</td><td>0</td><td>16</td>

 

Appreciate any help you can give me!

 

Thanks,

Tejama

Link to comment
Share on other sites

<pre>
<?php
$string = 'Ortiz</a></td><td>90</td><td>330</td><td>61</td><td>106</td><td>32</td><td>0</td><td>16</td>';
preg_match('/Ortiz.+((?<!\d)\d+)/', $string, $matches);
array_shift($matches);
print_r($matches);
?>
</pre>

Link to comment
Share on other sites

Thanks, for the string I submitted that actually returns the proper value.  However, I did leave something out.  That is that the string I'm trying to parse has characters after 16 as well:

 

Ortiz</a></td><td>90</td><td>330</td><td>61</td><td>106</td><td>32</td><td>0</td><td>16</td><td>18</td><td>20</td>

 

So basically, I'm looking for a regex that will parse this line to return the value between the seventh set of <td>.

Link to comment
Share on other sites

<pre>
<?php
$string = 'Ortiz</a></td><td>90</td><td>330</td><td>61</td><td>106</td><td>32</td><td>0</td><td>16</td><td>18</td><td>20</td>';
preg_match('#Ortiz.*?(?:<td>.*?</td>){6}<td>(\d+)#', $string, $matches);
array_shift($matches);
print_r($matches);
?>
</pre>

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.