Regex Search dummie question

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
David.P
Posts: 72
Joined: 09 Dec 2006 11:21

Regex Search dummie question

Post by David.P »

Hi forum,

just a simple question (hopefully): How can I search files contents for something like

Code: Select all

(Peter OR Paul) AND Martha
Will I have to use Regex, and if yes, what would be the syntax?

Second, is it possible to search in "Office" AND "Text" files simultaneously?

Thanks heaps already,

Cheers David.P

highend
Posts: 14956
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Regex Search dummie question

Post by highend »

Are the names on the same line?
E.g. this regex would find files that contain lines like:

Paul searches for Martha
Peter loves Martha
etc.

Code: Select all

(Peter|Paul)(?=.*Martha)
If you want to look it up:
| = or
(?=.*text) = positive lookahead, .* takes anything before "text" appears
One of my scripts helped you out? Please donate via Paypal

David.P
Posts: 72
Joined: 09 Dec 2006 11:21

Re: Regex Search dummie question

Post by David.P »

Thanks highend,
highend wrote:Are the names on the same line?
No, just anywhere in the file!

Is it possible to carry out this search?

highend
Posts: 14956
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Regex Search dummie question

Post by highend »

This could work:

Code: Select all

(Peter|Paul).*[\s|\S](?=.*Martha)
One of my scripts helped you out? Please donate via Paypal

highend
Posts: 14956
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Regex Search dummie question

Post by highend »

So, does that work for you?
One of my scripts helped you out? Please donate via Paypal

xman
Posts: 133
Joined: 28 Nov 2009 22:57

Re: Regex Search dummie question

Post by xman »

highend wrote:This could work:

Code: Select all

(Peter|Paul).*[\s|\S](?=.*Martha)
This is I believe imperfect (tested it). It will match Martha only on current line or the next one, but not anywhere further. Also, character | doesn't belong here: [\s|\S], unless you want to match "|".

This will locate Martha anywhere, ignoring any number of newlines and other characters:

Code: Select all

(Peter|Paul)[\s\S]*?Martha
Or alternatively, using lookahead:

Code: Select all

(Peter|Paul)(?=[\s\S]*?Martha)
Character ? is there so it will not search throught the entire text, but just till the next occurence.

And this will locate Martha after OR before Peter/Paul, which is what OP requested:

Code: Select all

((Peter|Paul)[\s\S]*?Martha|Martha[\s\S]*?(Peter|Paul))

David.P
Posts: 72
Joined: 09 Dec 2006 11:21

Re: Regex Search dummie question

Post by David.P »

This is great, thanks guys -- but OMG!, is there no simpler way to do a Boolean search?

xman
Posts: 133
Joined: 28 Nov 2009 22:57

Re: Regex Search dummie question

Post by xman »

Probably not :/

Also, as per the help file, there is this:

Code: Select all

Note: Since larger files are read chunkwise (performance!) there are certain limits to the scope of your pattern: A pattern is  guaranteed to be found if it matches a range of 1,024 bytes! It also *might* be found if it matches a range of 1,025 to 32,768 bytes! It will certainly not be found if it matches only an even larger range.

David.P
Posts: 72
Joined: 09 Dec 2006 11:21

Re: Regex Search dummie question

Post by David.P »


highend
Posts: 14956
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Regex Search dummie question

Post by highend »

Maybe it's only supported for name & location?

At least it doesn't seem to work in the content field.

@xman
Thanks for correcting the necessary regex.
One of my scripts helped you out? Please donate via Paypal

Post Reply