Jump to content

preg_match() problem...


Link

Recommended Posts

For some reason, when it does the preg_match() it doesn't pick up the last . after p.m. ...why?

 

<?php
$str = "Meeting with Bryan and Co. June 10th from 8:00 a.m. to 9:00 p.m.";

if (preg_match("/\b(from)?\s*([0-9]{1,2}:[0-9]{2})\s*(a\.?m\.?|p\.?m\.?)?\s*(to)\s*([0-9]{1,2}:[0-9]{2})\s*(a\.?m\.?|p\.?m\.?)?\b/", $str, $matches)) {
print $matches[0];
$str = preg_replace("/\s*".$matches[0]."\s*/", " ", $str);
}
?>

 

Which outputs:

 

from 8:00 a.m. to 9:00 p.m

 

What happened to the trailing .?

Link to comment
https://forums.phpfreaks.com/topic/55860-preg_match-problem/
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.