Regular Expressions

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

elitecodex
New php-forum User
New php-forum User
Posts: 68
Joined: Tue Jul 09, 2002 8:45 am
Location: East Coast, USA
Contact:

Regular Expressions

Postby elitecodex » Tue Sep 03, 2002 11:24 am

I have a question. I thought that I understood regular expressions, but I guess I dont. Could anyone lend a helping hand?

I have this:

Code: Select all

preg_match("/([0-9]{2})([a-zA-Z])([0-9]{1,4})/i", $_POST["job_number"], $mat);
var_dump($mat);


and the input ($_POST["job_number"]) would be 02PR500 and I want to split that up. By "02" then "PR" then "500". Of course 02 and 500 could be any value between 1 and 9000. What am I doing wrong? Any help is greatly appreciated.

Will

vvlad
New php-forum User
New php-forum User
Posts: 3
Joined: Fri Sep 06, 2002 3:21 am

Postby vvlad » Fri Sep 06, 2002 3:43 am

hi
you write correct regexp, only one mistake
there are several letters and try to match only one
here is correct regexp
"^([0-9]{2})([a-zA-Z]+)([0-9]{1,4})$/i"

elitecodex
New php-forum User
New php-forum User
Posts: 68
Joined: Tue Jul 09, 2002 8:45 am
Location: East Coast, USA
Contact:

Postby elitecodex » Fri Sep 06, 2002 4:45 am

hello

I thank you for your response. I know have some questions though. If memory serves me right, then "^" and "$" match the beginning and end of a string, respectively. What does the "+" do?

Do you know where I could find some good docs on regular expressions? Im kinda new to them and want to start to really learn the fun stuff :)

Also, what the difference between perl regular expressions and regular expressions? I ask b/c I noticed that they both are supported in PHP and was wondering if they have a syntax difference or what.

Thanks for your response

Will


Return to “PHP coding => General”

Who is online

Users browsing this forum: Bing [Bot], krotbacca and 4 guests