Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

search pattern in Notepad++

1) First I want to search a text with pattern such as

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

in a large text using Notepad++, a sample of the text shown below:

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

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

but not as

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

where first abs has unmatched parenthesis.

Please give some advice!

Thanks in advance

like image 353
arslan Avatar asked Sep 20 '16 10:09

arslan


2 Answers

Yes, you should switch Search Mode to Regular expression (at the bottom of Find dialog) and use regular expression as a pattern.

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}

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


Answer to the first part updated question

Actualy, pattern above doesn't give the results that you describe. .? matches zero or one any character and parentheses are interpreted as special symbols. Thus, your pattern matches strings like 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. 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+)app\(abs\((.*)\),abs\((.*)\)\)

Also, it would be better to enable lazy matching by putting ? after *, like this:

^app\(abs\((.*?)\),abs\((.*?)\)\)
like image 190
Andrii Avatar answered Sep 23 '22 05:09

Andrii


Is that possible in 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

like image 31
Matthias Herrmann Avatar answered Sep 23 '22 05:09

Matthias Herrmann