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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23816781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:51:58  来源:igfitidea点击:

How can I Find/Replace part of a wildcard search in Notepad++

htmlcssregexbackgroundnotepad++

提问by MatrixNinja

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

简单的例子。
当我编辑 CSS 时。无论数字序列如何,我都想查找所有“背景”,所以我正在使用.*

~~~Example:
Findbackground: #.*;

~~~例子:
查找background: #.*;

(Found 4 Matches)

Line12: background: #111111;

Line24: background: #222222;

Line36: background: #333333;

Line48: background: #444444;

(找到 4 个匹配项)

第 12 行:背景:#111111;

Line24:背景:#222222;

Line36:背景:#333333;

第 48 行:背景:#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: #.*; */

~~~例如:
替换为/* 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: #.*; */

不给我这个:

第 12 行:/* 背景:#111111;*/

第 24 行:/* 背景:#222222;*/

第 36 行:/* 背景:#333333;*/

第 48 行:/* 背景:#444444;*/

相反,它给了我这个:

第 12 行:/* 背景:#.*;*/

第 24 行:/* 背景:#.*;*/

第 36 行:/* 背景:#.*;*/

第 48 行:/* 背景:#.*;*/

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

我不知道如何防止代码中的数字(无论组合的种类如何)发生变化,只在代码周围添加 /* */

采纳答案by ubergoober

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:

对于您的替换,请使用:

/*  */

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.

您未能做的是捕获匹配的值以在替换正则表达式中重用。搜索中的 () 将存储在可用作 \1 的参数中。

回答by phew

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

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

Replace: /* background: #\1 */

代替: /* background: #\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。