Inconsistent regular expression behavior with Find/Replace

Having trouble installing Oxygen? Got a bug to report? Post it all here.
Frank Ralf
Posts: 460
Joined: Thu Jan 23, 2014 2:29 pm
Location: Hamburg
Contact:

Inconsistent regular expression behavior with Find/Replace

Post by Frank Ralf »

Hi,

I've noticed that the regular expressions do behave differently in Find/Replace within a single file and Find/Replace in Files, most notably the behavior of a point "." As the "Dot matches all" option (Perl's /s modifier) is missing from Find/Replace in Files this makes it quite cumbersome to write a regex which spans multiple lines in the source code.

Is there a workaround or do I have to use another editor for more complex regex find/replace operations across multiple files? It would be great, if Find/Replace in Files would provide the same options as the usual Find/Replace.

Kind regards,
Frank
Frank Ralf
parson AG
www.parson-europe.com
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Inconsistent regular expression behavior with Find/Repla

Post by adrian »

Hi,

The reason the option 'Dot matches all' (Perl's single line mode) is not readily available in Find Replace in Files is that it forces the entire document to be treated as a single line and loaded in memory, instead of searching the file incrementally. This can frequently lead to situations where the file would not fit the available memory.
For the Find/Replace in editor this doesn't make any difference since the file is already loaded in memory.

If you want to force that option, you can use the directive (?s) at the beginning of the regular expression.

I believe there is also the alternative solution of using '(.|\n)' in the expression instead of '.' with that option.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Frank Ralf
Posts: 460
Joined: Thu Jan 23, 2014 2:29 pm
Location: Hamburg
Contact:

Re: Inconsistent regular expression behavior with Find/Repla

Post by Frank Ralf »

Hi Adrian,

Thanks for the explanation and the pointers for a workaround. I will try that.

Kind regards,
Frank
Frank Ralf
parson AG
www.parson-europe.com
Frank Ralf
Posts: 460
Joined: Thu Jan 23, 2014 2:29 pm
Location: Hamburg
Contact:

Re: Inconsistent regular expression behavior with Find/Repla

Post by Frank Ralf »

(?s) works like a charm and helps tremendously!

Many thanks again for your help,
Frank
Frank Ralf
parson AG
www.parson-europe.com
Post Reply