“Find and Replace” is a huge time saver but sometimes you need something more flexible than replace ‘x’ with ‘y’.
This is where Regular Expressions come in handy.
This article explains how to use wildcards and other advanced features that gives super powers to the humble “Find and Replace” modal.

This article uses a free program called Notepad++. If you don’t have it, you can download it here.
How to Wrap paragraphs with Find/Replace
Consider this example…

Say you have a document formatted like the image above. Imagine you needed to wrap each paragraph in <p> tags. A normal “Find and Replace” can’t do that, but it’s possible with “Regular Expressions”.
Here’s how to do it in Notepad++
- Find and Replace
In Notepad++ press Ctr+H to open the “Find and Replace” window.
- Click “Regular Expression” option
Under Search Mode: choose “Regular expression” and then check the “matches newline” checkbox.
- Add <p> tag to beginning of each line
Find what: \n..
Replace with: \n \n<p> - Notice Added <p> tag
You should see <p> tags at the beginning of each line
- Add Closing </p> tag
Find what: \n \n
Replace with: </p> \n \n - Notice Closing </p> tags
You should see closing </p> tags at the end of each line.
So what’s happening here?
‘\n‘ looks for a line break.
‘.‘ is a wildcard that matches any single character.
So ‘\n..‘ looks for a line break followed by two characters of text.
In other words, we’re saying “find a new line with content”, (not a blank line) then replace it with 2 new lines and a “<p>” tag.
To close the paragraphs, we’re saying “find 2 line breaks in a row” (because we just made sure to add to breaks in between each paragraph) and replace it with a closing </p>”.
Cheat Sheet
Here’s a list of useful expressions you may want to use in your find and replace escapades…
\n
line break
\t
Tab
\d
A digit in the 0-9 range (a number)
\D
Not a digit. Anything that’s not a number (including spaces).
\l
A lowercase letter.
NOTE: this will fall back on “a word character” if the “Match case” search option is off.
\L
Not a lower case letter. See note above.
\u
An uppercase letter.
\U
Not an uppercase letter.
\w
A word character, which is a letter, digit or underscore. This appears not to depend on what the Scintilla component considers as word characters. Same as [[:word:]].
\W
Not a word character.
\s
A spacing character: space, EOLs and tabs count.
\S
Not a space.
\h
Horizontal spacing. This only matches space, tab and line feed.
\H
Not horizontal whitespace.
\v
Vertical whitespace.
\V
Not vertical whitespace
$
Only applies to character at the end of a line. (ex. ‘!$’ would replace all explamation points at the end of a line.)
^
Online applies to character at the beginning of a line (ex. ‘^<p>’ would replace any ‘<p>’ at the beginning of a line.)
Replace Multiple Spaces with Tab
Want another useful tip?
Let’s say you have code that was indented with lots of spaces. Replacing all those spaces with tabs, would make the code much cleaner.
Let’s say you want to replace every 4 spaces with 1 tab.
- In the Find what field type: ([ ]{4})
2. In the Replace with field type: \t
Don’t forget to have the Regular Expression radio button selected (just like before).
If you need a different number of spaces, just change the number. For example if you want to replace 6 spaces use the following: ([ ]{6})
Credit: I found this tip at https://datacadamia.com/ide/notepad/replace.
Bonus Tip!
Alternative Online Tools That Make Text Conversion Easier
Sometimes expressions can be a little hard to figure out. If you’re looking for some simple online tools, you might try diffchecker.com, titlecase.com, and textmechanic.com.
I’ll talk about each…
Check for differences between 2 sets of text
The other day, I wanted to check for differences between 2 websites. I had a WordPress theme that I knew I’d made some changes to, but I couldn’t remember exactly what they were.
I found a useful website called https://www.diffchecker.com that let me copy and paste the code for the two sites and highlighted the differences for me.

Changing All Caps to Titlecase
I frequently get text from clients in ALL CAPS, and I often want to change it to Title Case or sentence case without having to retype it.
TitleCase.com will convert your text to Title Case, UPPERCASE, lowercase, or Sentence case. It will even do programming specific conversions like camelCase, PascalCase, hyphen-case, or snake_case. Pretty useful!

Miscellaneous Text Editing Tools with Text Mechanic
Textmechanic.com has a variety of bulk text editing tools.
Here’s a few of the tools they have…
- Remove Extra spaces tool
- Count characters, words, sentences, and lines
- Remove duplicate lines
- Add Prefix/Suffix into Line
Let Us Know Your Thoughts
As I was reviewing my analytics, I noticed this article has become quite popular, but strangely has far fewer comments than our other popular articles. I realized that might be because there was no invitation to comment. So I’ve decided to fix that.
Was this article useful?
Do you have any useful tricks for Advanced Find & Replace functionality?
Let us know in the comments below…
2 Comments
Very useful. Thanks!!
Need regular expression replace for below requirement
My text:
I would like to remove id attribute
expecting text: