Jump to content

Syntax question


phpknight

Recommended Posts

Hi,

 

I am new the regex part of PHP and am trying to get a simple regex working with a set of four to six alphanumeric characters.  This works:

 

^([^b]{4,6}) -- 5-6 characters--not b

 

but once I do this:

 

^([:alnum:]{4,6})

 

it does not work.  I've also tried doubling the brackets around alnum.  I know I am missing something simple.  I would appreciate some help.

Link to comment
https://forums.phpfreaks.com/topic/65761-syntax-question/
Share on other sites

i think you want this

 

$data = "test";
if (preg_match('/^[a-z0-9]{4,6}$/i', $data)) {
# Successful match
} else {
# Match attempt failed
}

 

or

$data = "test";
if (eregi('^[a-z0-9]{4,6}$', $data)) {
# Successful match
} else {
# Match attempt failed
}

 

 

$data = "test"; //works
$data = "testing"; //fails
$data = "tst"; //fails

Link to comment
https://forums.phpfreaks.com/topic/65761-syntax-question/#findComment-328846
Share on other sites

From the mod_rewrite docs:

 

Pattern is a perl compatible regular expression.

For more information about regular expressions, have a look at the perl regular expression manpage ("perldoc perlre").

 

...which points directly to Perl's regular expressions--not a "compatible" version. There is either a mix-up in terminology, or a more flexible definition of compatible involved.

Link to comment
https://forums.phpfreaks.com/topic/65761-syntax-question/#findComment-329093
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.