Notepad++ uses the Boost C++ Regular Expression Library for its regex functionality. Below is a cheat sheet with commonly used regex patterns in Notepad++:
Regex Basics
.
(dot):- Matches any single character, except for a newline.
*
:- Matches 0 or more occurrences of the preceding character.
+
:- Matches 1 or more occurrences of the preceding character.
?
:- Matches 0 or 1 occurrence of the preceding character.
Character Classes
[ ]
:- Defines a character class.
[^ ]
:- Defines a negated character class.
Anchors
^
:- Matches the start of a line.
$
:- Matches the end of a line.
Quantifiers
{n}
:- Matches exactly n occurrences.
{n,}
:- Matches n or more occurrences.
{n,m}
:- Matches between n and m occurrences.
Escape Characters
\
:- Escapes a special character.
Common Metacharacters
\d
:- Matches any digit (equivalent to
[0-9]
).
- Matches any digit (equivalent to
\D
:- Matches any non-digit.
\w
:- Matches any word character (alphanumeric + underscore).
\W
:- Matches any non-word character.
\s
:- Matches any whitespace character.
\S
:- Matches any non-whitespace character.
Groups and Capturing
( )
:- Groups patterns together.
\1
,\2
, …:- Refers to the contents of capturing groups (backreferences).
Examples
1. Match Email Addresses:
[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}
2. Extract Dates (YYYY-MM-DD):
\d{4}-\d{2}-\d{2}
3. Replace Digits:
\d+
4. Extract URLs:
https?://[^\s]+
5. Match Words with ‘ing’:
\b\w+ing\b
These examples can be used in the Find/Replace dialog in Notepad++ with the “Regular expression” search mode selected. Adjust the patterns based on your specific requirements. For more detailed information, refer to the Notepad++ Regular Expressions documentation.