PHP Regular Expressions Using +, *, And ? – String Function

 
Regexp                                              Result
 
preg_match("/[A-Z]+/", "123")                       False
 
preg_match("/[A-Z][A-Z0-9]+/i", "A123")             True
 
preg_match("/[0-9]?[A-Z]+/", "10GreenBottles")      True; matches "0G"
 
preg_match("/[0-9]?[A-Z0-9]*/i", "10GreenBottles")  True
 
preg_match("/[A-Z]?[A-Z]?[A-Z]*/", "")              True; zero or one match, then zero or one match, then zero or more means that an empty string matches

Share Article/Example:
  • DotNetKicks
  • DZone
  • StumbleUpon
  • Print
  • Add to favorites
  • Digg
  • del.icio.us
  • Twitter
  • Facebook
  • LinkedIn
  • Posterous
  • Slashdot

Filed Under: Php Basics Examples

RSSComments (0)

Trackback URL

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.