Search in files/folders for files containing two strings using regular expressions

Discussion, questions and support.
Post Reply
Message
Author
daredan
Posts: 2
Joined: 13.09.2017, 12:16

Search in files/folders for files containing two strings using regular expressions

#1 Post by daredan » 13.09.2017, 12:36

Hi,

I have been googling through different forums to find out on how I can find two strings in containing text in a list of data files.

It's apparently fairly easy to find them with the OR function as this is merely done with a |, eg (String1|String2).
However I want to find only files which contain both strings in them, but the AND function seems to be more complex to set up as regular expression. I have found examples (eg https://stackoverflow.com/questions/469 ... d-operator) mentioning that (?=String1)(?=String2) should work at least in Perl/Java, but I couldn't make it work in FreeCommander.

Which brings me back to the original question: How to find files which contain two specific strings using regular expressions?

Thanks in advance.

afh
Posts: 106
Joined: 30.06.2014, 20:50
Location: Romania

Re: Search in files/folders for files containing two strings using regular expressions

#2 Post by afh » 16.09.2017, 15:30

(String1|String2).*(String1|String2) should work...

daredan
Posts: 2
Joined: 13.09.2017, 12:16

Re: Search in files/folders for files containing two strings using regular expressions

#3 Post by daredan » 18.09.2017, 17:04

Thanks for the reply. Unfortunately I couldn't make it work as the pic illustrates. https://imgur.com/a/ckHAW

shreyathakare_91
Posts: 1
Joined: 01.03.2019, 08:00

Re: Search in files/folders for files containing two strings using regular expressions

#4 Post by shreyathakare_91 » 01.03.2019, 08:04

The syntax (?si), at beginning of the regex, are modifiers which ensures that :

The dot ( . ) special character matches, absolutely, any single character ( standard or EOL )

The search will be perform, in an insensitive case way ( If you need a sensitive search, just use the syntax (?s-i) )

Then (Word1) matches the string Word1, stored as group 1, due to the parentheses, ONLY IF followed by the first string Word2, found afterwards, also stored as group 2, due to the “Look-ahead” construction (?=.*?(Word2))

After the alternative symbol |, the case (?2)(?=.*?(?1)) just represents the opposite case, where we’re searching for the string Word2, followed, further on, with the string Word1. We use a specific regex construction (?#), named a called subpattern.
java development
java training institute

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 25 guests