Match One of Alternate Literal Strings ( ( | ) )
You can put a set of literal strings, each separated by a pipe bar (|), between parentheses. The string matches if it contains any one of the alternate literal strings.
Regular Expression | Match | Not a Match |
---|---|---|
a(bc|de|fg)x | abcx, adex, afgx | ax, abx, abcdex |
I (love|hate) carrots | I love carrots | I like carrots |
Many special characters and literal characters can be mixed together to form a regular expression. Really long, complex regular expressions can be built to match any conceivable string.
A special character is sometimes part of a literal string. If you want to include special characters in a regular expression to be treated as literal characters, you insert a backslash ( \ ) in front of the special character. ...
Get Spring Into Linux® now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.