Simple Example.
When I'm editing CSS.
I want to Find all "backgrounds" regardless of the number sequence, so I'm using .*
~~~Example:
Find background: #.*;
(Found 4 Matches)
Line12: background: #111111;
Line24: background: #222222;
Line36: background: #333333;
Line48: background: #444444;
"Found (#) of lines matching"
Great, works perfect!
(The next part is the where I'm having trouble)
Now I want to Replace, or in this case wrap all these lines with /* */, without removing the individual numbers.
(To remove certain backgrounds, when I'm done editing the page.)
~~~Example:
Replace With /* background: #.*; */
Doesn't give me this:
Line12: /* background: #111111; */
Line24: /* background: #222222; */
Line36: /* background: #333333; */
Line48: /* background: #444444; */
Instead, it give me this:
Line12: /* background: #.*; */
Line24: /* background: #.*; */
Line36: /* background: #.*; */
Line48: /* background: #.*; */
I can't figure out how to keep the numbers (regardless of the variety of combinations) from changing in the code and only add /* around the code */
Wildcards are used to represent the characters or sequences of characters in that string. Because different combinations of characters can be represented by a variety of wildcard combinations, there is often more than one way of identifying a particular string of text within a document.
use \. * is a wildcard that matches zero of more of the preceding character. So a* would match zero or more a and .
Open the text file in Notepad++. In the top menu bar, click Search and select Replace. In the Replace window, on the Replace tab, enter the text you want to find and the text you want to use as a replacement. See our using search and replace and advanced options for further information and help.
Search pattern: background: #([0-9]+);
Replace: /* background: #\1 */
([0-9]+) will match the numbers and save it in a group \1. You can re-use \1 in the "Replace" input.
Change your search to something little less reliant on having one space (say you hit tab on one or two).
(background:.*?;)
And for your replace, use:
/* \1 */
What you were failing to do was to capture the matched value to reuse in your replace regex. The () in the search will store in a parameter which can be used as \1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With