Preg_Match Limit

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Preg_Match Limit

Post by tecktalkcm0391 »

I have this code:

Code: Select all

<?php
$text = "AB-12345";

if(preg_match("/^([A-Za-z]+)\-([0-9]+)$/", $text)){
	echo "yes";
}

?>
Is there a way to make it so that the number after the "-" has to be a digit between 1-5 digits? Only 5 digits?

Thanks!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

http://www.perl.com/doc/manual/html/pod/perlre.html wrote:The following standard quantifiers are recognized:

* Match 0 or more times
+ Match 1 or more times
? Match 1 or 0 times
{n} Match exactly n times
{n,} Match at least n times
{n,m} Match at least n but not more than m times
[0-9]{1,5}
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

Thanks!
Post Reply