Prev | Current Page 299 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"


??? [a-z] matches any character from lowercase a through lowercase z.
??? [A-Z] matches any character from uppercase A through uppercase Z.
??? [A-Za-z] matches any character from uppercase A through lowercase z.
Of course, the ranges shown here are general; you could also use the range [0-3] to
match any decimal digit ranging from 0 through 3, or the range [b-v] to match any
lowercase character ranging from b through v. In short, you can specify any ASCII
range you wish.
Quantifiers
Sometimes you might want to create regular expressions that look for characters
based on their frequency or position. For example, you might want to look for strings
containing one or more instances of the letter p, strings containing at least two p??™s, or
even strings with the letter p as their beginning or terminating character. You can
make these demands by inserting special characters into the regular expression. Here
are several examples of these characters:
??? p+ matches any string containing at least one p.
??? p* matches any string containing zero or more p??™s.
??? p? matches any string containing zero or one p.
234 CHAPTER 9 ?–  STRINGS AND REGULAR EXPRESSIONS
??? p{2} matches any string containing a sequence of two p??™s.
??? p{2,3} matches any string containing a sequence of two or three p??™s.
??? p{2,} matches any string containing a sequence of at least two p??™s.


Pages:
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311