Find and Replace Online
This example demonstrates the find and replace operation from String Tools, pre-loaded with a simple replacement scenario. Paste any text, enter a search pattern (literal or regex), and specify the replacement string. The output updates instantly as you type.
How It Works
The tool splits your input into lines and applies the search/replace operation across the entire text. When regex mode is enabled, the search field is interpreted as a regular expression pattern. The replacement field can include backreferences ($1, $2) to reference captured groups.
Literal vs Regex Matching
In literal mode, special characters lose their regex meaning. A search for file.txt matches exactly those characters. In regex mode, the dot matches any single character, so file.txt would also match file1txt or fileAtxt.
Common Regex Patterns for Find and Replace
| Pattern | Use Case |
|---|---|
\\s+ | Match one or more whitespace characters |
\\bword\\b | Match whole word only |
(?i)pattern | Case-insensitive match (or use the flag toggle) |
(capture) | Capture a group for use in replacement |
[^a-zA-Z] | Match any non-letter character |
Practical Example: Cleaning CSV Data
Say you have comma-separated values with inconsistent spacing:
name , age , city
Alice , 30 , New York
Bob , 25 ,San Francisco
Search for \\s*,\\s* (comma surrounded by optional whitespace) and replace with , to normalize all separators. Then search for ^\\s+|\\s+$ with the multiline flag to trim leading and trailing spaces from each line.
How to Use
- Paste your text into the input area
- Enter the search pattern in the search field (literal text or regex)
- Enter the replacement string (use $1, $2 for captured groups)
- Toggle regex mode, global replace, or case-insensitive flags as needed
- Copy the transformed output from the result area
Common Questions
Can I preview replacements before copying?
Yes. The tool shows the transformed output in real time. Each replacement is reflected immediately so you can verify the result before copying it.
How do I escape special regex characters?
Wrap your search text in the regex escape sequence: each special character (. * + ? [ ] ( ) { } ^ $ | \) should be preceded by a backslash. Or use literal mode, which treats all characters as plain text.
What happens with empty matches?
If a regex pattern matches an empty string (e.g., a*), the tool replaces each empty match and moves forward, which can produce unexpected results. Use a+ instead to require at least one character.