...

View Full Version : Regular expression help (errors)



tspek
02-04-2010, 09:33 PM
I'm getting this error


Warning: preg_match [function.preg-match-all]: Unknown modifier '.' in /home3/thephou0/public_html/pelotonpoints/includes/usac-scrape.php on line 24

I'm just trying to find a date in mm/dd/yyyy

code looks like this:




**LINE 24** ---> $date_regex ='/(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)[0-9]{2}/';
$n = preg_match($date_regex,$date_grab,$date);


$date_grab = "07/26/2009 -BLAH BLAH BLAH"

Fou-Lu
02-04-2010, 09:42 PM
You're delimiter is the / character. As soon as it hit it again (ie here: '/(0[1-9]|1[012])[- /), it considers everything else to be outside of the patterns and is expecting modifiers (such as msiU, etc). Correct it by either choosing a new delimiter (other common ones are # and |), or by escaping you're current / with \, so \/ instead.

tspek
02-04-2010, 09:48 PM
You're delimiter is the / character. As soon as it hit it again (ie here: '/(0[1-9]|1[012])[- /), it considers everything else to be outside of the patterns and is expecting modifiers (such as msiU, etc). Correct it by either choosing a new delimiter (other common ones are # and |), or by escaping you're current / with \, so \/ instead.

Is this a regular expression thing or a PHP thing, because I grabbed this expression from a library of regular expressions.

And thanks.

Fou-Lu
02-04-2010, 09:55 PM
That I couldn't tell you for certain. I would suspect it is a regular expression thing; logically the pattern thinks its complete when you've provided it with an ending delimiter.

MattF
02-05-2010, 12:21 AM
I would suspect it is a regular expression thing;

It is.

tspek
02-05-2010, 01:06 AM
It is.

Then I guess that library sucks :thumbsup:

MattF
02-05-2010, 01:23 AM
Then I guess that library sucks :thumbsup:

Unless the author just had an off moment. It hapens to us all on occasion. :D If the same type of error is present in several regex, however, then the quality of the guidance would be debatable.

Fou-Lu
02-05-2010, 05:34 AM
Unless the author just had an off moment. It hapens to us all on occasion. :D If the same type of error is present in several regex, however, then the quality of the guidance would be debatable.

Yeah, if it was in a PHP page (.php, or any plain text), its definitely wrong. If it was on a webpage, it could have been a stripping issue (magic_quotes_runtime can potentially do that to you).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum