Regular Expressions (Regex)

Regular Expressions (Regex) are patterns which are widely used in many programming languages and softwares to search, match, and manipulate text.

Following are the examples of softwares that uses regex

Basic steps

Step 1: Open Find/Replace dialog in txt file

Step 2: At the bottom of the dialog, under Search Mode, select

Step 3: Apply the following regex syntax to search, match or manipulate text

Basic Regex Syntax

Symbol Meaning Example
. Matches any single character. c.t → cat, cut, cot
^ Matches the start of a line. ^Hello → Line starts with "Hello".
$ Matches the end of a line. world$ → Line ends with "world".
\d Matches any digit (0–9). \d+ → 123, 4567
\w Matches any word character (a-z, A-Z, 0-9, _). \w+ → hello123
\s Matches any whitespace (space, tab). \s+ → spaces
\b Matches a word boundary. \bword\b → Exact match for "word".
\ Escapes special characters. \. → Matches a literal period.
* Matches 0 or more occurrences. ab*c → ac, abc, abbc
+ Matches 1 or more occurrences. ab+c → abc, abbc
? Matches 0 or 1 occurrence. colou?r → color, colour
[] Matches a character set. [aeiou] → Matches vowels.
` ` Alternation (OR).
() Groups expressions. (ab)+ → ab, abab

Examples to show the use of regex syntax

1. for removing two spaces before any word
2. to remove timestamp in txt file
3. to remove two spaces between two lines
4. to remove text with square brackets
5. Add Text at the Start of Each Line
6. Add Text at the End of Each Line
7. Remove Blank Lines
8. Remove Numbers from Text
9. Match Emails in Text
10. Find and Replace Trailing Spaces
semanticclimate outreach notebook

← Back