alohatofu Posted April 21, 2007 Share Posted April 21, 2007 /^2007.[0-9]{12}/ on number: 2007042000834420You can will yield 2007042000834420 correct?? Why is it not doing it for me :-( Link to comment https://forums.phpfreaks.com/topic/48000-regex/ Share on other sites More sharing options...
genericnumber1 Posted April 21, 2007 Share Posted April 21, 2007 probably because you have the . in there, meaning there has to be an extra character... 2007 042000834420 would work 2007z042000834420 would work 2007=042000834420 would work... try /^2007[0-9]{12}/ that'd match 2007042000834420 but make sure you also want it to match 200704200083442020394u2on3 oi432h89op4 2h843ho -- because it will Link to comment https://forums.phpfreaks.com/topic/48000-regex/#findComment-234578 Share on other sites More sharing options...
alohatofu Posted April 21, 2007 Author Share Posted April 21, 2007 That still didn't output the right number here's what I have //matches ac ticket number $acticketpattern = '/^2007[0-9]{12}/'; if (preg_match("$acticketdpattern", "Refer to ticket number: 2007042000834420You can", $matches_acticket)) { echo "Match was found <br />"; echo $matches_acticket[0]; } Link to comment https://forums.phpfreaks.com/topic/48000-regex/#findComment-234579 Share on other sites More sharing options...
Guest prozente Posted April 21, 2007 Share Posted April 21, 2007 ^ means match from the beginning of the string, so you'll want to remove it in this case. You also have a D in the variable name you're passing to preg_match. <?php $acticketpattern = '/2007[0-9]{12}/'; if (preg_match($acticketpattern, "Refer to ticket number: 2007042000834420You can", $matches_acticket)) { echo "Match was found <br />"; echo $matches_acticket[0]; } Link to comment https://forums.phpfreaks.com/topic/48000-regex/#findComment-234583 Share on other sites More sharing options...
alohatofu Posted April 21, 2007 Author Share Posted April 21, 2007 I have I have DSLAMs: 14 today the pattern that I have is /DSLAMs:\s*(\d+)/ but that will output DSLAMs: 14 How would I do so that It will just the number? Link to comment https://forums.phpfreaks.com/topic/48000-regex/#findComment-234596 Share on other sites More sharing options...
Guest prozente Posted April 21, 2007 Share Posted April 21, 2007 () means to create a back reference, the full pattern is matched as 0, since that's the first back reference it'd match under 1. So if your variable was $matches it'd be $matches[1] Link to comment https://forums.phpfreaks.com/topic/48000-regex/#findComment-234607 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.