Finding and replacing text is one of the most common tasks when working with content, code, and data. Online tools let you perform both simple string replacements and complex transformations using regular expressions.
Simple string replacement
Basic replacement works on the principle of “find an exact match and replace it.” This is useful for:
- replacing one word with another
- correcting typos throughout the entire text at once
- replacing old URLs with new ones after moving a website
For example, if you need to replace all occurrences of http://example.com with https://example.com, simple replacement will do it instantly.
What are regular expressions?
Regular expressions (regex, regexp) are a language for describing text patterns. They let you search for patterns rather than exact strings: “any digits,” “a word at the beginning of a line,” or “an email address.”
Basic metacharacters:
| Symbol | Meaning |
|---|---|
. | Any character except a line break |
* | 0 or more repetitions |
+ | 1 or more repetitions |
? | 0 or 1 repetition |
^ | Start of line |
$ | End of line |
\d | Digit (0-9) |
\w | Letter, digit, or underscore |
\s | Whitespace character |
Practical regex replacement examples
Removing extra spaces
Поиск: \s{2,}
Замена: (один пробел)This regular expression finds two or more consecutive spaces and replaces them with one.
Replacing all URLs in text
Поиск: https?://[^\s]+
Замена: [ссылка удалена]The pattern https? means “http” or “https” (the ? sign makes s optional).
Masking email addresses
Поиск: ([a-zA-Z0-9._%+-]+)@([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})
Замена: ***@$2Here, $2 is a capture group containing the domain. The username is replaced with ***, while the domain is preserved.
Removing HTML tags
Поиск: <[^>]+>
Замена: (пусто)Formatting phone numbers
Поиск: (\d{1})(\d{3})(\d{3})(\d{2})(\d{2})
Замена: +$1 ($2) $3-$4-$5Converts 79161234567 to +7 (916) 123-45-67.
Regular expression flags
When working with regex, it is important to account for flags:
- g (global) — find all matches, not just the first
- i (ignore case) — ignore letter case
- m (multiline) —
^and$apply to each line - s (dotAll) —
.also matches line breaks
Capture groups and backreferences
Parentheses create capture groups that you can refer to in the replacement string:
Поиск: "(\w+)\s(\w+)"
Замена: "$2 $1"Swaps two words in quotation marks: "Иван Петров" → "Петров Иван".
When regex is not needed
Regular expressions are a powerful tool, but they are not always warranted. It is easier to replace one string with another without regex. Use regex when:
- You need to search by pattern rather than exact match
- You need to replace text while preserving parts of the match
- You need to process several similar patterns with one rule
For regex testing and debugging, also see the Regular Expression Tester.
Bulk replacement in multiple files
If you need to change text in several sources at once, you can use an online find-and-replace tool together with the CSV/JSON converter to prepare the data.
Tool on reChecker
The find-and-replace tool on reChecker supports both simple string replacement and full regular expressions with flags. Paste any text, specify a search pattern and replacement string, and the result will appear instantly.