devWhiz Posted April 28, 2011 Share Posted April 28, 2011 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 More sharing options...
AbraCadaver Posted April 28, 2011 Share Posted April 28, 2011 Assuming r4_ is always there, then this might work: preg_match_all('/id="r4_([\d]+)">/', $string, $matches); print_r($matches[1]); Other variations depending on the formats. Link to comment https://forums.phpfreaks.com/topic/235004-preg_match-help/#findComment-1207736 Share on other sites More sharing options...
devWhiz Posted April 28, 2011 Author Share Posted April 28, 2011 yep r4 is the same all the time, Thanks man! I aqppreciate the help, it worked I need to learn preg match.. It would help out alot for the stuff I do, any tips? Link to comment https://forums.phpfreaks.com/topic/235004-preg_match-help/#findComment-1207746 Share on other sites More sharing options...
AbraCadaver Posted April 28, 2011 Share Posted April 28, 2011 This is a good source: http://www.regular-expressions.info/ Also, there are quite a few online regex testers: http://www.myregextester.com/index.php Link to comment https://forums.phpfreaks.com/topic/235004-preg_match-help/#findComment-1207779 Share on other sites More sharing options...
.josh Posted April 28, 2011 Share Posted April 28, 2011 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.