
regex in notepad++
Searching a string using the ‘Find‘ or ‘Find & Replace‘ function in text editors highlights the relevant match (e.g. searching ‘le‘ highlights it inside words such as ‘apple‘, ‘please’ etc). However, some advanced editors such as Notepad++ (I mention Notepad++ in my examples since its my favourite so far!) supports the use of regex, which recently saved me hours of manually replacing strings and numeric values in files containing HTML and JacaScript codes.
Regex characters can be used to create advanced matching criteria. The following table introduces some of them with practical examples. But before starting make sure that you change the Search Mode from Normal to Regular expression in your Find or Find & Replace dialogue box.
- [ ]
- ^
- $
- .
- \d
- \w
- \s
- *
- +
- \<
- \>
- ( )
- \
The square brackets can be used to match ONE of multiple characters. For instance, [abc] matches any of the characters a, b or c. Hence, b[eo]n will match words like ben and bon, but not been or beon. Ranges can also be used, [a-z] is any lower case character and so on.
The caret can be used inside the square brackets to exclude characters from the match. For instance, hell[^o] means the string ‘hell’ will be ignored if followed by the letter ‘o’. Another example is [^A-Za-z] which will exclude all alphabetic characters.
However, if not placed inside a set, ^ can be used to matches the start of a line.
This matches the end of a line.
The period or dot matches any character.
Matches any single digit.
Matches any single alphanumeric characters or underscore.
Matches whitespaces including tabs and line breaks.
The asterisk or star sign matches 0 or more times. For example, Ba*m matches Bm , Bam , Baam etc.
The plus sign matches 1 or more times. For example, lo+l matches lol , lool , loool etc.
Matches the start of a word. For example, \< directly followed by 'sh' matches 'she' but does not matches 'wish'.
Matches the end of a word. For example, sh\> matches ‘wish’ and does not matches ‘she’.
The round brackets can be used in the Find & Replace function to tag a match. tagged matches can then be used in replace with \1, \2 etc.
For example, If you write 123xxxRRR in the search and 123\1HHH in the ‘Replace with’ filed, the result will be: 123xxxHHH.
The backslash can be used to escape regex characters. For example to match 1+1=2, the correct regex is 1\+1=2. Otherwise, the plus sign will have a special meaning.
Further, the following two examples should be giving you a better idea of how to use regex in your editor:
- Find: Win([0-9]+) Replace with: Windows\1
- Find: [a-z]+(\d\d)\> Replace with: Windows\1
Will search for strings like Win2000, Win2003 and changes them to Windows2000, Windows2003…
Will search for all alphanumerics followed by 2 digits only at the end such as Win98 and Win07 and changes them to Windows98, Windows07…

[...] ausgeführt und alles in Ordnung. Hier habe ich interessante Infos [...]
Thanks you very much for spending the time to explain this Notepad++ RegEx function so well & so clearly — a big help!!
[...] http://blog.creativeitp.com/posts-and-articles/editors/understanding-regex-with-notepad/ Share this:TwitterFacebookLike this:LikeBe the first to like this. This entry was posted on Monday, September 17th, 2012 at 3:55 pm and posted in RegEx. You can follow any responses to this entry through the RSS 2.0 feed. « Finally Definitely Executes Last [...]
I have a standard Apache log file to filter. The regular expresion that match the entire line is “^(\S+) \S+ \S+ \[([^\]]+)\] “([A-Z]+)[^"]*” \d+ \d+$”, but now I need to select the lines that does not match, I need the “inverse” selection of this regex. How could I search for those lines that not match the regex?
Thanks for this micro guide.
Do you know how to ignore case?
In egrep UNIX utility just -i parameter:
egrep -i ‘^(From|Subject|Date):’ emails.txt
Thanks in advance!
How do I remove all lines starting with “#house:” in Notepad++?
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Thanks a lot for these great explanations. However I tried:
“Find what” #house:(.*)$
“Replace with” (empty)
which did remove the *contents of* the lines but left a blank line each time. Any help? TIA,
Versailles, Fri 30 Nov 2012 19:19:15:00 +0100
Find What : => ^(#house:)(.*)\r\n
Replace With :=>
[...] http://blog.creativeitp.com/posts-and-articles/editors/understanding-regex-with-notepad/ [...]
@John Ortiz:
John, you can uncheck ‘Match case’ checkbox in the ‘Find’ window to ignore the case while searching.
A correction: “For example, If you write 123(…)RRR in the search and 123\1HHH in the ‘Replace with’ field, 123xxxRRR will be: 123xxxHHH.”
Thanks a bunch dude
“Anonymous” 23 Apr 2013 at 15:33 GMT, your « ^(#house:)(.*)\r\n » doesn’t work in my test (Notepad++ 6.3.2 UNICODE, Windows 7 64bit Ultimate), neither in Regular expression nor in Extended modes. Did you really test it?
Versailles, Sun 05 May 2013 14:53:10 +0200