Match any character in Notepad++ replace
Matching any character while searching and replacing in Notepad++ editor:
[\s\S]*?
- Matching a whitespace \s (space, tab \t, newline \r or \n, etc) or not a whitespace \S. That is, any character. Matching 0 or more times, made lazy.
- In fact, other similar character sets are also going to work: [\w\W]*? and [\d\D]*?
Example
Removing unnecessary P tags in the following HTML code:
<div class="example">
<ul>
<li><p>Text</p></li>
<li>
<p>Text</p>
</li>
</ul>
</div>
- Ctrl + H
- Find What: <li>[\s\S]*?<p>(.*)</p>[\s\S]*?</li>
- Replace With: <li>\1</li>
- Wrap around
- Search Mode: Regular expression
- Replace All
After running Replace with that regex, the code is going to end up like this:
<div class="example">
<ul>
<li>Text</li>
<li>Text</li>
</ul>
</div>
Links
- Regex to match any character including new lines [duplicate] stackoverflow.com/questions/8303488/regex-to-match-any-character-including-new-lines
- matching any character including newlines in a Python regex subexpression, not globally stackoverflow.com/questions/33312175/matching-any-character-including-newlines-in-a-python-regex-subexpression-not-g
- How do I match any character across multiple lines in a regular expression? stackoverflow.com/questions/159118/how-do-i-match-any-character-across-multiple-lines-in-a-regular-expression
Operating systems
- Windows