Jump to content

preg_match help


devWhiz

Recommended Posts

if I have this info in a doc

 

" id="r4_20770702">

 

how would I use preg_match or preg_match_all to parse ot the number 20770702

 

and would it be different to parse ot more than one id in that form like...

 

" id="r4_20770702">
" id="r4_35133964">
" id="r4_38461866">
" id="r4_31859736">

Link to comment
Share on other sites

couple things to note about the pattern AbraCadaver provided:

 

preg_match_all('/id="r4_([\d]+)">/', $string, $matches);

 

\d doesn't have to be wrapped in a character class, it's kind of it's own character class, so you can just do \d+ 

 

But \d technically matches more than numbers, so if you want to be more specific, use [0-9] instead:

 

preg_match_all('/id="r4_([0-9]+)">/', $string, $matches);

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.