HandyFile Find and Replace
Regular Expression Examples
Below are given some examples of using regular expressions in various situations.
Compress whitespace (spaces, tabs, line breaks).
- Find pattern
\s+- Replace pattern
(single space; or \x20 for better replace text readability)
Find any HTML colour constant.
- Find pattern
\#{[0-9A-Fa-f]}+
Replace all HTML colour constants with the new one (#AFEEEE).
- Find pattern
\#{[0-9A-Fa-f]}+- Replace pattern
#AFEEEE
Replace all occurrences of full stop before the lowercase letter with comma, truncating separating spaces to only one (useful for scanned documents).
- Find pattern
{\.\s#}(\L[a-z])- Replace pattern
\, \1
Strip HTML tags.
- Find pattern
{\<}{\/?}{.#}{\>}- Replace pattern
empty
Replace <P> tags with <DIV> tags, preserving tag attributes.
- Find pattern
\<P\s(.#)\>(.#)\<\/P\>- Replace pattern
<DIV \1>\2</DIV>
Colorize HTML tags for use inside HTML page: symbols with blue, tag with red, convert < and > to entities.
- Find pattern
\<({\/}?)(.#)\>- Replace pattern
<span style="color:blue"><\1</span>
<span style="color:red">\2</span><span style="color:blue">></span>
Insert comment with the file name at the beginning of all .cpp files.
- Find pattern
^(.)
Note the use of the match-and-store-first-symbol operators: ^ acts as a positioner only.- Replace pattern
/**************************************\r\n
This file name: \f
\r\n**************************************/\r\n\r\n\r\n\1






