October 2006
Intermediate to advanced
888 pages
16h 55m
English
The typical regular expression is delimited by a pair of slashes; the %r form can also be used. Table 3.1, “Basic Regular Expressions,” gives some simple examples:
| Regex | Explanation |
|---|---|
| /Ruby/ | Match the single word Ruby |
| /[Rr]uby/ | Match Ruby or ruby |
| /^abc/ | Match an abc at beginning of line |
| %r(xyz$) | Match an xyz at end of line |
| %r|[0-9]*| | Match any sequence of (zero or more) digits |
It is also possible to place a modifier, consisting of a single letter, immediately after a regex. Table 3.2 shows the most common modifiers:
| Modifier | Meaning |
|---|---|
| i | Ignore case in regex |
| o | Perform expression substitution only once |
| m | Multiline mode (dot matches newline) |
| x | Extended regex (allow ... |
Read now
Unlock full access