Jump to content

Regular Expression


jmaccs64

Recommended Posts

if (preg_match('~^([a-g]|h([a-e]))~i',$name)) {
  // matched
}

 

Here is a breakdown of the pattern Crayon Violent supplied:

 

~^([a-g]|h([a-e]))~i

 

~ = delimiter

 

^ = match must start at the beginning of string

 

[a-g] = letter must be 'a' through 'g' (because of the ^ the match has to be at the beginning of the string)

 

| = OR

 

h([a-e]) = letter must be an 'h' followed by 'a' through 'e' (because of the ^ the match has to be at the beginning of the string)

 

~ = delimiter

 

i = matching will be case insensitive

Link to comment
https://forums.phpfreaks.com/topic/214059-regular-expression/#findComment-1114099
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.