…
…
Regular expressions are patterns used to match character combinations in string. When searching for a match that requires more than a direct match, such as finding one or more b's or white space, you can include special characters in the pattern.
For instance, the pattern /ab*c/ can be used to match a single "a" followed by zero or more "b"s, then "c": the * after "b" denotes "0 or more occurrences of the preceding item."
When searching for a match that requires more than a direct match, you can include special characters in the pattern, such as locating one or more b's or white space.
For example, you could use the pattern /ab*c/ to match a single "a" followed by zero or more "b"s followed by "c": the * after "b" implies "0 or more occurrences of the preceding item." In the string "cbbabbbbcdebc", this pattern will match the substring "abbbbc."
[abc] |
A single character of: a, b, or c |
[^abc] |
Any single character except: a, b, or c |
[a-z] |
Any single character in the range a-z |
[a-zA-Z] |
Any single character in the range a-z or A-Z |
^ |
Start of line |
$ |
End of line |
\A |
Start of string |
\z |
End of string |
. |
Any single character |
\s |
Any whitespace character |
\S |
Any non-whitespace character |
\d |
Any digit |
\D |
Any non-digit |
\w |
Any word character (letter, number, underscore) |
\W |
Any non-word character |
\b |
Any word boundary |
(...) |
Capture everything enclosed |
(a|b) |
a or b |
a? |
Zero or one of a |
a* |
Zero or more of a |
a+ |
One or more of a |
a{3} |
Exactly 3 of a |
a{3,} |
3 or more of a |
a{3,6} |
Between 3 and 6 of a |
options: i
case insensitive m
make dot match newlines x
ignore whitespace in regex o
perform #{...} substitutions only once
Computers are useless. They can only give you answers.
Pablo Picasso
…
…