- Published on
Regex
152 words1 min read
Regular expressions are used when we want to search for specific lines of text containing a particular pattern.Here are some of the basic regular expressions:
| Metacharacter | Description |
|---|---|
| . | Matches any single character except for a newline. |
| * | Matches zero or more occurrences of the preceding character or group. |
| + | Matches one or more occurrences of the preceding character or group. |
| $ | Anchors the match at the end of a line. |
| ^ | Anchors the match at the beginning of a line. |
| \S | Matches any non-whitespace character. |
| \s | Matches any whitespace character (space, tab, newline). |
| ? | Makes the preceding character or group optional (zero or one occurrence). |
| [a-z] | Matches any lowercase letter in the specified range. |
| [A-Z] | Matches any uppercase letter in the specified range. |
| [A-Za-z] | Matches any letter (both uppercase and lowercase). |
| [0-9] | Matches any digit. |
| \ | Escapes a metacharacter, allowing you to match it as a literal character. |