Regexp... Am I correct?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mrskumm
Forum Newbie
Posts: 10
Joined: Tue Jul 22, 2003 5:40 am
Location: Sweden

Regexp... Am I correct?

Post 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!!
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Yes, your regexp to english translation looks correct.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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
mrskumm
Forum Newbie
Posts: 10
Joined: Tue Jul 22, 2003 5:40 am
Location: Sweden

Post by mrskumm »

Thank you both, now I know that I can start using my regexp instead of strlen etc... *lol*

Thanks!
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

This is a handy tool for trying out expressions: http://www.weitz.de/regex-coach/#install
Post Reply