This way we can quantify the number of times a block occurs; this
example matches 'monkeymonkeymonkey': /(monkey){3}/.
Continuing the shortcuts theme, there are certain characters that, if escaped, take on
a whole new role. If we want to search for a whole word, we can use \w+. By itself \w
is a character class that will match any word character. Word characters are letters,
digits and underscores; sometimes locale may make a difference to what constitutes
a word, for example accented characters may or may not be included.
Shortcut Description Character Class
\w Word characters Letters, digits, and underscores
\W Opposite of \w --------
\d Numbers Digits 0-9
\D Opposite of \d --------
\s Spaces Whitespace (not including new line characters)
\S Opposite of \s --------
Our pattern is case sensitive, so to allow any case we could do this /[a-zAZ][
oO][nN][kK][eE][yY]/. That's rather messy; instead we can use pattern
modifiers, which are characters that can be placed after the pattern delimiters: /[az]
onkey/i.
Pages:
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442