简体   繁体   English

Notepad ++中的搜索模式

[英]search pattern in Notepad++

1) First I want to search a text with pattern such as 1)首先,我想搜索带有图案的文本

   app(abs(something),abs(something))

in a large text using Notepad++, a sample of the text shown below: 在使用Notepad ++的大文本中,下面显示的文本示例如下:

app(abs(any length of characters here),abs(any length of characters here)),
tapp(abs(any length of characters here),abs(any length of characters here)),
app(abs(any length of characters here),app(any length of characters here)),
app(abs(any length of characters here),some(any length of characters here)),
app(abs(any length of characters here)) ,abs(any length of characters here))

when I use "app(abs((. ?)),abs((. ?)))" to search it finds first and second line in above sample. 当我使用“app(abs((。 ?)),abs((。 ?)))”搜索时,它会在上面的示例中找到第一行和第二行。 The second line is not what I am searching. 第二行不是我要搜索的。 what is wrong with my expression? 我的表情有什么问题?

2) If possible ,I want the opened and closed parenthesis ( ) after each "abs" should matched, such as 2)如果可能的话,我想要在每个“abs”匹配之后打开和关闭括号(),例如

   "app(     abs(..(..)..),abs(..(..(...)..)..)   )"

but not as 但不是

   "app(abs((), abs())"

where first abs has unmatched parenthesis. 其中第一个abs有无与伦比的括号。

Please give some advice! 请给出一些建议!

Thanks in advance 提前致谢

Yes, you should switch Search Mode to Regular expression (at the bottom of Find dialog) and use regular expression as a pattern. 是的,您应该将Search Mode切换为Regular expression (在“ Find对话框的底部)并使用正则表达式作为模式。

Assuming that asterisk in your pattern means any single character, you should replace * with . 假设模式中的星号表示任何单个字符,则应替换* . (matches any single character in the regular expression syntax) and put \\ before each parenthesis ( ( and ) are special characters and have to be escaped using \\ ). (匹配正则表达式语法中的任何单个字符)并在每个括号之前放置\\()是特殊字符,并且必须使用\\来转义)。 Thus, you will get: 因此,你会得到:

str1\(str2\(.....\),str2\(........\)\)

To make it less ugly, you can replace 5 dots with .{5} 为了减少丑陋,你可以用5点代替.{5}

str1\(str2\(.{5}\),str2\(.{8}\)\)


Answer to the first part updated question 回答第一部分更新的问题

Actualy, pattern above doesn't give the results that you describe. Actualy,上面的模式没有给出你描述的结果。 .? matches zero or one any character and parentheses are interpreted as special symbols. 匹配零或一个任何字符和括号被解释为特殊符号。 Thus, your pattern matches strings like appabsX,abs . 因此,您的模式匹配appabsX,abs等字符串。

It should be modified like this: 它应该像这样修改:

app\(abs\((.*)\),abs\((.*)\)\)

it finds first and second line in above sample 它在上面的样本中找到了第一行和第二行

Actually, it finds a part of the second line between t and , and it's correct behavior. 实际上,它找到了t和之间第二行的一部分,这是正确的行为。 If you want to ignore such cases, you should somehow specify the beginning of string you are searching. 如果你想忽略这种情况,你应该以某种方式指定你正在搜索的字符串的开头。 Some examples: 一些例子:

^ matches the begging of line: ^匹配行的乞讨:

^app\(abs\((.*)\),abs\((.*)\)\)

(\\s+) matches at least one white space character (\\ s +)匹配至少一个空格字符

(\s+)app\(abs\((.*)\),abs\((.*)\)\)

Also, it would be better to enable lazy matching by putting ? 另外,最好通过放置启用延迟匹配 ? after * , like this: *之后,像这样:

^app\(abs\((.*?)\),abs\((.*?)\)\)

Is that possible in Notepad++? 这可能在Notepad ++中吗?

Yes it is possible with regular expressions. 是的,可以使用正则表达式。

How to do it? 怎么做?

Take a look at that link: Regular Expressions Notepad 看看那个链接: 正则表达式记事本

Look at that link if you want to learn more about learning, Building and testing regular expressions: 如果您想了解有关学习,构建和测试正则表达式的更多信息,请查看该链接:

RegExr RegExr

Something like this: 像这样的东西:

^app\(abs\((.*?)\),abs\((.*?)\)\)

checkbox in search window ". matches new line" need unchecked. 搜索窗口中的复选框“。匹配新行”需要取消选中。

Screenshot http://image.prntscr.com/image/6dfda1d0bc4544919903fb0ee85432b4.png 截图http://image.prntscr.com/image/6dfda1d0bc4544919903fb0ee85432b4.png

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

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