Page 1 of 1

Regexp... Am I correct?

Posted: Fri Aug 01, 2003 4:20 pm
by mrskumm
I am matching variables, and it's my first regexp, but it seems to work...

The string MUST be:
10 numbers then either followed by a star (*) or not followed by anything...

The code:
$regexp_matches=preg_match("/^[0-9]{10}\*?$/", $regexp_string[$i]);
And it seems to work, just not sure if I have overlooked anything... Thanks!!

Posted: Fri Aug 01, 2003 7:00 pm
by nielsene
Yes, your regexp to english translation looks correct.

Posted: Fri Aug 01, 2003 11:38 pm
by m3rajk
fyi: for future ref, perl shorts:

\d = [0-9]
\w = [A-Za-z0-9_]
\s = [\f\t\n\r]

in the next set ^ = not
\D = ^\d
\W = ^\w
\S = ^\s

Posted: Sat Aug 02, 2003 8:37 am
by mrskumm
Thank you both, now I know that I can start using my regexp instead of strlen etc... *lol*

Thanks!

Posted: Sat Aug 02, 2003 1:28 pm
by McGruff
This is a handy tool for trying out expressions: http://www.weitz.de/regex-coach/#install