Regular expressions (regex or regexp) are powerful tools used for pattern matching and searching within text
Source:
Regex Cheatsheet
Character | Meaning | Example | ||
---|---|---|---|---|
* | Match zero, one, or more of the previous | Ah* matches "Ahhhhh" or "A" | ||
? | Match zero or one of the previous | Ah? matches "A1" or "Ah" | ||
+ | Match one or more of the previous | Ah+ matches "Ah" or "Ahhh" but not "A" | ||
\ | Used to escape a special character | Hungry\? matches "Hungry?" | ||
. | Wildcard character, matches any character | do.* matches "dog" , "door" , "dot" , etc. | ||
() | Group characters | See example for ` | ` | |
[] | Matches a range of characters | [cbf]ar matches "car" , "bar" , or "far" | ||
[0-9]+ matches any positive integer | ||||
[a-zA-Z] matches ASCII letters a-z and A-Z | ||||
[^0-9] matches any character not 0-9 | ||||
` | ` | Matches previous OR next character/group | `(Mon) | (Tues)daymatches “Monday”or “Tuesday”` |
{} | Matches a specified number of occurrences of the previous | [0-9]{3} matches "315" but not "31" | ||
[0-9]{2,4} matches "12" , "123" , and "1234" | ||||
[0-9]{2,} matches "12345..." | ||||
^ | Matches the beginning of a string or negation in a range | ^http matches strings starting with "http" , such as a URL | ||
[^0-9] matches any character not 0-9 | ||||
$ | Matches the end of a string | ing$ matches "exciting" but not "ingenious" |