如何在Notepad++中找到/替换通配符搜索的一部分

时间:2022-08-03 19:51:31

Simple Example.
When I'm editing CSS. I want to Find all "backgrounds" regardless of the number sequence, so I'm using .*

简单的例子。当我编辑CSS。我想找到所有的“背景”,而不考虑数字序列,所以我使用。*

~~~Example:
Find background: #.*;

~ ~ ~的例子:找到背景:#。*;

(Found 4 Matches)

(发现4匹配)

Line12: background: #111111;

Line12:背景:# 111111;

Line24: background: #222222;

Line24:背景:# 222222;

Line36: background: #333333;

Line36:背景:# 333333;

Line48: background: #444444;

Line48:背景:# 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; */

Line12:/ *背景:# 111111;* /

Line24: /* background: #222222; */

Line24:/ *背景:# 222222;* /

Line36: /* background: #333333; */

Line36:/ *背景:# 333333;* /

Line48: /* background: #444444; */

Line48:/ *背景:# 444444;* /

Instead, it give me this:

相反,它给了我这个:

Line12: /* background: #.*; */

Line12:/ *背景:#。*;* /

Line24: /* background: #.*; */

Line24:/ *背景:#。*;* /

Line36: /* background: #.*; */

Line36:/ *背景:#。*;* /

Line48: /* background: #.*; */

Line48:/ *背景:#。*;* /

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 */

我不知道如何在代码中保持数字(不管组合的多样性)不变,只在代码*/周围添加/*

2 个解决方案

#1


3  

Change your search to something little less reliant on having one space (say you hit tab on one or two).

把你的搜索改为不那么依赖于一个空格的搜索(比如你按一两个空格的tab键)。

(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.

您没有做的是捕获匹配的值以便在replace regex中重用。搜索中的()将存储一个可以用作\1的参数。

#2


4  

Search pattern: background: #([0-9]+);

搜索模式:背景:#([0 - 9]+);

Replace: /* background: #\1 */

替换:/*背景:#\1 */

([0-9]+) will match the numbers and save it in a group \1. You can re-use \1 in the "Replace" input.

([0-9]+)将匹配数字并保存在组\1中。您可以在“替换”输入中重用\1。

#1


3  

Change your search to something little less reliant on having one space (say you hit tab on one or two).

把你的搜索改为不那么依赖于一个空格的搜索(比如你按一两个空格的tab键)。

(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.

您没有做的是捕获匹配的值以便在replace regex中重用。搜索中的()将存储一个可以用作\1的参数。

#2


4  

Search pattern: background: #([0-9]+);

搜索模式:背景:#([0 - 9]+);

Replace: /* background: #\1 */

替换:/*背景:#\1 */

([0-9]+) will match the numbers and save it in a group \1. You can re-use \1 in the "Replace" input.

([0-9]+)将匹配数字并保存在组\1中。您可以在“替换”输入中重用\1。