{"id":2459,"date":"2022-06-27T14:07:29","date_gmt":"2022-06-27T12:07:29","guid":{"rendered":"http:\/\/jakisproblem.pl\/?p=2459"},"modified":"2022-06-27T14:07:29","modified_gmt":"2022-06-27T12:07:29","slug":"using-regex-to-find-and-replace-text-in-notepad","status":"publish","type":"post","link":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/2022\/06\/27\/using-regex-to-find-and-replace-text-in-notepad\/","title":{"rendered":"Using Regex to find and replace text in Notepad++"},"content":{"rendered":"<header id=\"site-header\" role=\"banner\">\n<div id=\"primary-navigation\" role=\"navigation\">\n<div class=\"primary-menu-wrap primary-navigation clearfix\"><\/div>\n<\/div>\n<\/header>\n<div class=\"main-container\">\n<div id=\"page\" class=\"single clearfix\">\n<article class=\"ss-full-width\">\n<div id=\"content_box\">\n<div id=\"post-9260\" class=\"g post post-9260 type-post status-publish format-standard hentry category-installers tag-notepad tag-regex\">\n<div class=\"single_post\">\n<div class=\"post-single-content box mark-links entry-content\">\n<div class=\"thecontent\">\n<p>A quick cheat sheet for using <a href=\"https:\/\/notepad-plus-plus.org\/\" rel=\"nofollow\">Notepad++<\/a>\u00a0to find and replace text in Notepad++.<\/p>\n<p>In all examples, use select Find and Replace (Ctrl + H) to replace all the matches with the desired string or (no string).<\/p>\n<p>And also ensure the \u2018Regular expression\u2019 radio button is set.<\/p>\n<div id=\"attachment_9278\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-9278 size-full\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex2.png\" sizes=\"auto, (max-width: 573px) 100vw, 573px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex2.png 573w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex2-300x186.png 300w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex2-224x138.png 224w\" alt=\"\" width=\"573\" height=\"356\" aria-describedby=\"caption-attachment-9278\" \/><\/a><\/p>\n<p id=\"caption-attachment-9278\" class=\"wp-caption-text\">Using Regex to find and replace text<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p><a name=\"Start\"><\/a>Shortcuts to examples covered in this Notepad++ regex tutorial are as follows:<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#1\">1. Removing arbitrary whitespaces and tabs<\/a><br \/>\n<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#2\">2. Insert a newline for every line of text<\/a><br \/>\n<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#3\">3. Removing blank lines<\/a><br \/>\n<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#4\">4. Replace comma separated list with string list<\/a><br \/>\n<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#5\">5. Remove duplicate words<\/a><br \/>\n<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#6\">6. Replace with first word from each lines<\/a><br \/>\n<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#7\">7. Replace with last word from each line<\/a><br \/>\n<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#8\">8. Replace all duplicate lines with a single instance<\/a><br \/>\n<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#9\">9. Insert all text into a single line<\/a><br \/>\n<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#10\">10. Replace the first line in text<\/a><br \/>\n<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#11\">11. Trim additional spaces from sentences<\/a><br \/>\n<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#12\">12. Remove unwanted characters<\/a><br \/>\n<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#13\">13. Convert string to lower case except for acronyms &amp; abbreviations<\/a><br \/>\n<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#14\">14. Remove trailing whitespaces from lines with text and empty lines<\/a><\/p>\n<p><a name=\"1\"><\/a><strong>1. Removing arbitrary whitespaces and tabs<\/strong>\u00a0<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#Start\">(Back to top)<\/a><\/p>\n<p>In this example we replace the whitespaces and tabs between pairs of \u2018&gt; &lt;\u2018 strings<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9274\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex1.png\" sizes=\"auto, (max-width: 558px) 100vw, 558px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex1.png 558w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex1-300x226.png 300w\" alt=\"\" width=\"558\" height=\"421\" \/><\/a><\/p>\n<p>Regex match expression:<\/p>\n<p>(Switch off word wrap so you can see it merge into one line)<\/p>\n<div>\n<div id=\"highlighter_198955\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"xml plain\">&amp;gt;[ \\t]+&amp;lt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Replace with:<\/p>\n<div>\n<div id=\"highlighter_831531\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"xml plain\">&amp;gt;&amp;lt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Result<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex3-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9277\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex3-1.png\" sizes=\"auto, (max-width: 558px) 100vw, 558px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex3-1.png 558w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex3-1-300x226.png 300w\" alt=\"\" width=\"558\" height=\"421\" \/><\/a><\/p>\n<p><a name=\"2\"><\/a><strong>2. Insert a newline for every line of text<\/strong>\u00a0<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#Start\">(Back to top)<\/a><\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9282\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex4.png\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex4.png 481w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex4-300x238.png 300w\" alt=\"\" width=\"481\" height=\"381\" \/><\/a><\/p>\n<p>Regex match expression:<\/p>\n<div>\n<div id=\"highlighter_841240\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"xml plain\">(.)$<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Replace with:<\/p>\n<div>\n<div id=\"highlighter_605665\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"xml plain\">$1\\n<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Result:<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9283\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex5.png\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex5.png 481w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex5-300x238.png 300w\" alt=\"\" width=\"481\" height=\"381\" \/><\/a><\/p>\n<p><a name=\"3\"><\/a><strong>3. Removing blank lines<\/strong>\u00a0<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#Start\">(Back to top)<\/a><\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex6.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9286\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex6.png\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex6.png 481w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex6-300x238.png 300w\" alt=\"\" width=\"481\" height=\"381\" \/><\/a><\/p>\n<p>Regex match expression:<\/p>\n<div>\n<div id=\"highlighter_587107\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"xml plain\">^[ \\t]*$\\r?\\n*<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Replace with:<\/p>\n<div>\n<div id=\"highlighter_481768\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Result:<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9287\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex7.png\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex7.png 481w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex7-300x238.png 300w\" alt=\"\" width=\"481\" height=\"381\" \/><\/a><\/p>\n<p><a name=\"4\"><\/a><strong>4. Replace comma separated list with string list<\/strong>\u00a0<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#Start\">(Back to top)<\/a><\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex8.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9290\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex8.png\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex8.png 481w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex8-300x238.png 300w\" alt=\"\" width=\"481\" height=\"381\" \/><\/a><\/p>\n<p>Regex match expression:<\/p>\n<div>\n<div id=\"highlighter_639185\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"xml plain\">,[ \\t]+<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Replace with:<\/p>\n<p>\\n<\/p>\n<p>Result:<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex9.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9291\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex9.png\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex9.png 481w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex9-300x238.png 300w\" alt=\"\" width=\"481\" height=\"381\" \/><\/a><\/p>\n<p><a name=\"5\"><\/a><strong>5. Remove duplicate words<\/strong>\u00a0<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#Start\">(Back to top)<\/a><\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex10.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9297\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex10.png\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex10.png 481w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex10-300x238.png 300w\" alt=\"\" width=\"481\" height=\"381\" \/><\/a><\/p>\n<p>Regex match expression (simple):<\/p>\n<div>\n<div id=\"highlighter_275347\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"xml plain\">\\b(\\w+)\\s+\\1\\b<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Replace with:<\/p>\n<p>\\1<\/p>\n<p>Result:<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex11.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9298\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex11.png\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex11.png 481w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex11-300x238.png 300w\" alt=\"\" width=\"481\" height=\"381\" \/><\/a><\/p>\n<p><a name=\"6\"><\/a><strong>6. Replace with first word from each line<\/strong>\u00a0<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#Start\">(Back to top)<\/a><\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex12.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9300\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex12.png\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex12.png 481w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex12-300x238.png 300w\" alt=\"\" width=\"481\" height=\"381\" \/><\/a><\/p>\n<p>Regex match expression (simple):<\/p>\n<div>\n<div id=\"highlighter_51264\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"xml plain\">^([^ \\t]+).*<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Replace with:<\/p>\n<p>\\1<\/p>\n<p>Result:<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex13.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9301\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex13.png\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex13.png 481w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex13-300x238.png 300w\" alt=\"\" width=\"481\" height=\"381\" \/><\/a><\/p>\n<p><a name=\"7\"><\/a><strong>7. Replace with last word from each line<\/strong>\u00a0<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#Start\">(Back to top)<\/a><\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex14.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9304\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex14.png\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex14.png 481w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex14-300x238.png 300w\" alt=\"\" width=\"481\" height=\"381\" \/><\/a><\/p>\n<p>Regex match expression (simple):<\/p>\n<div>\n<div id=\"highlighter_506831\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"xml plain\">(.* )(\\w+)$<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Replace with:<\/p>\n<div>\n<div id=\"highlighter_764968\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"xml plain\">'$2'<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Result:<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex15.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9305\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex15.png\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex15.png 481w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex15-300x238.png 300w\" alt=\"\" width=\"481\" height=\"381\" \/><\/a><\/p>\n<p><a name=\"8\"><\/a><strong>8. Replace all duplicate lines with a single instance<\/strong>\u00a0<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#Start\">(Back to top)<\/a><\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex16.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9314\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex16.png\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex16.png 481w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex16-300x238.png 300w\" alt=\"\" width=\"481\" height=\"381\" \/><\/a><\/p>\n<p>Regex match expression:<\/p>\n<div>\n<div id=\"highlighter_494878\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"xml plain\">(?sm)(^[^\\r\\n]*)[\\r\\n](?=.*^\\1)<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Replace with:<\/p>\n<div>\n<div id=\"highlighter_6880\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Result:<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex17.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9315\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex17.png\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex17.png 481w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex17-300x238.png 300w\" alt=\"\" width=\"481\" height=\"381\" \/><\/a><\/p>\n<p><a name=\"9\"><\/a><strong>9. Insert all text into a single line<\/strong>\u00a0<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#Start\">(Back to top)<\/a><\/p>\n<p>Check that your word wrap is switched off so that you actually see the text get modified.<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex18.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9366\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex18.png\" sizes=\"auto, (max-width: 475px) 100vw, 475px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex18.png 475w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex18-300x241.png 300w\" alt=\"\" width=\"475\" height=\"382\" \/><\/a><\/p>\n<p>Regex match expression:<\/p>\n<p>\\R<\/p>\n<p>Replace with:<\/p>\n<div>\n<div id=\"highlighter_60662\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Result:<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex19.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9367\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex19.png\" sizes=\"auto, (max-width: 475px) 100vw, 475px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex19.png 475w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex19-300x241.png 300w\" alt=\"\" width=\"475\" height=\"382\" \/><\/a><\/p>\n<p><a name=\"10\"><\/a><strong>10. Replace the first line in text<\/strong>\u00a0<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#Start\">(Back to top)<\/a><\/p>\n<p>In this example we just replace the match with empty text.<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex20.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9377\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex20.png\" sizes=\"auto, (max-width: 559px) 100vw, 559px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex20.png 559w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex20-300x226.png 300w\" alt=\"\" width=\"559\" height=\"421\" \/><\/a><\/p>\n<p>Regex match expression:<\/p>\n<p>\\A.*<\/p>\n<p>Replace with:<\/p>\n<div>\n<div id=\"highlighter_714870\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Result:<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex21.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9378\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex21.png\" sizes=\"auto, (max-width: 559px) 100vw, 559px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex21.png 559w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex21-300x226.png 300w\" alt=\"\" width=\"559\" height=\"421\" \/><\/a><\/p>\n<p><a name=\"11\"><\/a><strong>11. Trim additional spaces from sentences<\/strong>\u00a0<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#Start\">(Back to top)<\/a><\/p>\n<p>In this example we remove trailing and leading whitespaces from sentences.\u00a0<a href=\"https:\/\/medium.com\/factory-mind\/regex-cookbook-most-wanted-regex-aa721558c3c1\" rel=\"nofollow\">Original link<\/a>.<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex22.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9381\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex22.png\" sizes=\"auto, (max-width: 558px) 100vw, 558px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex22.png 558w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex22-300x226.png 300w\" alt=\"\" width=\"558\" height=\"421\" \/><\/a><\/p>\n<p>Regex match expression:<\/p>\n<p>^[\\s]*(.*?)[\\s]*$<\/p>\n<p>Replace with:<\/p>\n<div>\n<div id=\"highlighter_792686\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Result:<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex23.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9382\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex23.png\" sizes=\"auto, (max-width: 558px) 100vw, 558px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex23.png 558w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex23-300x226.png 300w\" alt=\"\" width=\"558\" height=\"421\" \/><\/a><\/p>\n<p><a name=\"12\"><\/a><strong>12. Remove unwanted characters<\/strong>\u00a0<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#Start\">(Back to top)<\/a><\/p>\n<p>We may wish to remove all special characters except alphanumeric characters, full stops and colons\/semi-colons, spaces, tabs, newlines etc:<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex24-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9518\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex24-1.png\" sizes=\"auto, (max-width: 558px) 100vw, 558px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex24-1.png 558w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex24-1-300x226.png 300w\" alt=\"\" width=\"558\" height=\"421\" \/><\/a><\/p>\n<p>Regex match expression:<\/p>\n<p>[^0-9a-zA-Z \\t\\n]+<\/p>\n<p>Replace with:<\/p>\n<div>\n<div id=\"highlighter_876939\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Result:<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex25.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9519\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex25.png\" sizes=\"auto, (max-width: 558px) 100vw, 558px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex25.png 558w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex25-300x226.png 300w\" alt=\"\" width=\"558\" height=\"421\" \/><\/a><\/p>\n<p><a name=\"13\"><\/a><strong>13. Convert string to lower case except for acronyms &amp; abbreviations<\/strong>\u00a0<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#Start\">(Back to top)<\/a><\/p>\n<p>We may wish to ensure the text is converted to lower case except for acronyms &amp; abbreviations which are kept as upper case.<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9569\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex1.jpg\" alt=\"\" width=\"558\" height=\"421\" \/><\/a><\/p>\n<p>Regex match expression:<\/p>\n<p>\\b(?![A-Z]+\\b)[a-zA-Z]+<\/p>\n<p>Replace with:<\/p>\n<div>\n<div id=\"highlighter_676202\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"xml plain\">\\L$0<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Result:<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9570\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex2.jpg\" alt=\"\" width=\"558\" height=\"421\" \/><\/a><\/p>\n<p><a name=\"14\"><\/a><strong>14. Remove trailing whitespaces from lines with text and empty lines<\/strong>\u00a0<a href=\"https:\/\/www.technical-recipes.com\/2020\/using-regex-to-find-and-replace-text-in-notepad\/#Start\">(Back to top)<\/a><\/p>\n<p>As requested in the comments below, some regex to remove trailing whitespaces from lines with text and empty lines<\/p>\n<p>Answer originally given on this\u00a0<a href=\"https:\/\/stackoverflow.com\/questions\/9532340\/how-do-i-remove-trailing-whitespace-using-a-regular-expression\" rel=\"nofollow\">Stack Overflow link<\/a>.<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex26.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9710\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex26.jpg\" sizes=\"auto, (max-width: 558px) 100vw, 558px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex26.jpg 558w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex26-300x226.jpg 300w\" alt=\"\" width=\"558\" height=\"421\" \/><\/a><\/p>\n<p>Regex match expression:<\/p>\n<p>[ \\t]+$<\/p>\n<p>If you need to get rid of instances of ASCII character 160 (non-breaking spaces) just make the following adjustment to your regex match:<\/p>\n<p>[ \\t\\xA0]+$<\/p>\n<p>Replace with:<\/p>\n<p>\\1<\/p>\n<p>Result:<\/p>\n<p><a href=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex27.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9711\" src=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex27.jpg\" sizes=\"auto, (max-width: 558px) 100vw, 558px\" srcset=\"https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex27.jpg 558w, https:\/\/www.technical-recipes.com\/wp-content\/uploads\/2020\/06\/regex27-300x226.jpg 300w\" alt=\"\" width=\"558\" height=\"421\" \/><\/a><\/p>\n<\/div>\n<div class=\"shareit floating\">\n<div id=\"___plusone_0\"><\/div>\n<div id=\"fb-root\" class=\" fb_reset\">\n<div>\n<div><\/div>\n<\/div>\n<\/div>\n<div class=\"fb-like fb_iframe_widget\" data-send=\"false\" data-layout=\"button_count\" data-width=\"150\" data-show-faces=\"false\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/article>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">A quick cheat sheet for using Notepad++\u00a0to find and replace text in Notepad++. In all examples, use select Find and Replace (Ctrl + H) to replace all the matches with the desired string or (no string). And also ensure the \u2018Regular expression\u2019 radio button is set. Using Regex to find and replace text &nbsp; Shortcuts&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/2022\/06\/27\/using-regex-to-find-and-replace-text-in-notepad\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[130,129],"class_list":["post-2459","post","type-post","status-publish","format-standard","hentry","category-bez-kategorii","tag-notepad","tag-regular-expressions"],"_links":{"self":[{"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/posts\/2459","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/comments?post=2459"}],"version-history":[{"count":1,"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/posts\/2459\/revisions"}],"predecessor-version":[{"id":2460,"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/posts\/2459\/revisions\/2460"}],"wp:attachment":[{"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/media?parent=2459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/categories?post=2459"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/tags?post=2459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}