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
https://forums.phpfreaks.com/topic/235004-preg_match-help/
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
https://forums.phpfreaks.com/topic/235004-preg_match-help/#findComment-1207822
Share on other sites

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.