Prev | Current Page 307 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

Some potential matches
include fool, fooool, and foosball.
Modifiers
Often you??™ll want to tweak the interpretation of a regular expression; for example, you
may want to tell the regular expression to execute a case-insensitive search or to
ignore comments embedded within its syntax. These tweaks are known as modifiers,
and they go a long way toward helping you to write short and concise expressions. A
few of the more interesting modifiers are outlined in Table 9-1.
Table 9-1. Six Sample Modifiers
Modifier Description
i Perform a case-insensitive search.
g Find all occurrences (perform a global search).
m Treat a string as several (m for multiple) lines. By default, the ^ and $ characters
match at the very start and very end of the string in question. Using the m
modifier will allow for ^ and $ to match at the beginning of any line in a
string.
s Treat a string as a single line, ignoring any newline characters found within;
this accomplishes just the opposite of the m modifier.
x Ignore white space and comments within the regular expression.
U Stop at the first match. Many quantifiers are ???greedy???; they match the pattern
as many times as possible rather than just stop at the first match. You can
cause them to be ???ungreedy??? with this modifier.
CHAPTER 9 ?–  S TRINGS AND REGULAR EXPRESS IONS 241
These modifiers are placed directly after the regular expression??”for instance,
/string/i.


Pages:
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319