简体   繁体   English

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

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

Simple Example. 简单的例子。
When I'm editing CSS. 当我在编辑CSS时。 I want to Find all "backgrounds" regardless of the number sequence, so I'm using .* 我想查找所有“背景”,无论数字序列如何,所以我正在使用.*

~~~Example: ~~~实施例:
Find background: #.*; 查找 background: #.*;

(Found 4 Matches) (找到4个匹配项)

Line12: background: #111111; 第12行:背景:#111111;

Line24: background: #222222; Line24:背景:#222222;

Line36: background: #333333; 第36行:背景:#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: #.*; */ 替换为 /* background: #.*; */ /* 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:/ * background:#。*; */ * /

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

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

Line48: /* 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 */ 我无法弄清楚如何保持数字(不论组合的多样性)在代码中更改并且只在代码周围添加/ * * /

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. ([0-9] +)将匹配数字并将其保存在组\\ 1中。 You can re-use \\1 in the "Replace" input. 您可以在“替换”输入中重复使用\\ 1。

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. 搜索中的()将存储在一个可用作\\ 1的参数中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM