click below
click below
Normal Size Small Size show me how
LPI101 - table 5-6
Regular expression position anchors, character sets, modifiers
Question | Answer |
---|---|
\<\> | Match word boundaries. Word boundaries are defined as whitespace, the start of line, the end of line, or punctuation marks. The backslashes are required and enable this interpretation of < and >. |
[abc][a-z] | Single-character groups and ranges. In the first form, match any single character from among the enclosed characters a, b, or c. In the second form, match any single character from among the range of characters bounded by a and z (POSIX character classes |
[^abc][^a-z] | Inverse match. Match any single character not among the enclosed characters a, b, and c or in the range a-z. Be careful not to confuse this inversion with the anchor character ^, described earlier. |
. | Match any single character except a newline. |
* | Match an unknown number (zero or more) of the single character (or single-character regex) that precedes it. |
\? | Match zero or one instance of the preceding regex. |
\| | Alternation. Match either the regex specified before or after the vertical bar. |
\(regex\) | Grouping. Matches regex, but it can be modified as a whole and used in back-references. (\1 expands to the contents of the first \(\) and so on up to \9.) |
\+ | Match one or more instances of the preceding regex. |
\{n,m\} | Match a range of occurrences of the single character or regex that precedes this construct. \{n\} matches n occurrences, \{n,\} matches at least n occurrences, and \{n,m\} matches any number of occurrences from n to m, inclusively. |
^ | Match at the beginning of a line. This interpretation makes sense only when the ^ character is at the left-hand side of the regex. |
$ | Match at the end of a line. This interpretation makes sense only when the $ character is at the right-hand side of the regex. |