Case insensitive. Allow regex matching. Multiline matching.
Tool:
Find and replace text.
Purpose:
Find and replace text across line breaks with the option of regular expression (regex) matching.
Basic instructions:
Load working-text, enter find text into "Find this text or regex" field, enter replacement text into "and replace with" field and click "Find and replace" button.
Regex instructions:
Check "Allow regex matching" checkbox to enable.
A "regular expression" (regex) is a sequence of characters defines a search pattern within a matching action.
Within a regex phrase are literal and special characters of which the special characters define what actions are to be done.
Special characters []{}().*+?^=!:$\| will function as literal characters when escaped with a single backslash.
The simplest and most useful regex character is the pipebar | which is interpreted as "or" within the phrase.
To find literal characters ("a" or "b" or "c") within working-text, use the regex phrase a|b|c.
See example below.
Remember to escape special characters when used as literal characters within the phrase, thus ("1+1" or "1=1" or "1*1") will read as 1\+1|1\*1|1\=1.
Use the "Enter literal find text to escape special characters" tool at page bottom to escape a mix of literal and special characters used as literals.
A regex capture can be created by placing parentheses around part of a regex grouping to create a backreference to the matched text and applied as a placeholder ($1) within the replace text.
A common use for capture/placeholder would be to apply text around matched text.
For example to apply html bold tags around ("a" or "b" or "c") use the regex a|b|c but within parentheses looking as (a|b|c).
The replacement text will now use the matched text as the backreference placeholder written as $1 replacing itself with itself and whatever is included around it.
The replacement text will read as <b>$1</b> which will wrap bold tags around all instances of ("a" or "b" or "c") found within text.
Only nine captures/placeholders ($1-$9) will function, so $10+ need not be applied.
See examples:
Wrap text around captured placeholder text. and
Swap two regex captures using $1 and $2 placeholders.Regex examples:Replace ("a" or "b" or "c") with "d".
Working-text is:
A box of biscuits, a box of mixed biscuits and a biscuit mixer!
Enter regex a|b|c into "Find this text or regex" field, d into "and replace with" field and click "Find and replace" button to produce:
d dox of disduits, d dox of mixed disduits dnd d disduit mixer!
Wrap text around captured placeholder text.
Text captured within the regex parentheses can be placed back (backreference) into text as a placeholder with text wrapping around it.
This is useful for wrapping tags around text, escaping special text, etc.
In this example the HTML bold tag <b>text</b> will be wrapped around captured text using the placeholder "$1".
Working-text is:
Place bold tags around the words bold and tag.
Enter regex (\bbold\b|\btag\b) into "Find this text or regex" field, enter <b>$1</b> into "and replace with" field and click "Find and replace" button to produce:
Place <b>bold</b> tags around the words <b>bold</b> and <b>tag</b>.
Swap two regex captures using $1 and $2 placeholders.
Working-text is:
abcd
To swap letters "b" and "c" enter the regex grouping (b)(c) into find field, enter $2$1 into replace field and click "Find and replace" button to produce:
acbd
Replace differing text between two strings.
Working-text is:
1. start abc1 end
2. start ab2 end
3. start abc3 end
Goal is to replace differing text (in differing situations) between the strings/words "start" and "end".
To replace all instances (abc1,ab2,abc3) you will need to use the regex grouping .*? between strings within lines producing the regex phrase \bstart\b.*?\bend\b* to be entered in the find field.
In the replace field enter start (replacement text) end and click "Find and replace" button to produce:
1. start (replacement text) end
2. start (replacement text) end
3. start (replacement text) end
*Use \b to denote a word boundary so match will only occur with start/end and not within other words like starter or send.
Replace text if followed by another text.
Working-text is:
1. start abc1 end
2. start ab2 end
3. start abc3 end
To match a text followed by another text is a called "lookahead".
A lookahead phrase is written as a(?=b) for matching "a" if followed by "b" or a(?=b|c) for matching "a" if followed by "b" or "c".
Enter regex phrase a(?=2) in the find field and start (replacement text) end in the replace field, click "Find and replace" button to produce:
1. start abc1 end
2. start (replacement text) end
3. start abc3 end
Replace text if not followed by another text.
Working-text is:
1. start abc1 end
2. start ab2 end
3. start abc3 end
To match a text followed by another text is a called "negated lookahead".
A negated lookahead phrase is written as a(?!b) for matching "a" if not followed by "b" or a(?!b|c) for matching "a" if not followed by "b" or "c".
Enter regex phrase b(?!2) in the find field and start (replacement text) end in the replace field, click "Find and replace" button to produce:
1. start (replacement text) end
2. start ab2 end
3. start (replacement text) end