Page 1 of 1

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

Posted: 13.09.2017, 12:36
by daredan
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.

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

Posted: 16.09.2017, 15:30
by afh
(String1|String2).*(String1|String2) should work...

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

Posted: 18.09.2017, 17:04
by daredan
Thanks for the reply. Unfortunately I couldn't make it work as the pic illustrates. https://imgur.com/a/ckHAW

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

Posted: 01.03.2019, 08:04
by shreyathakare_91
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