Page 1 of 1

Inconsistent regular expression behavior with Find/Replace

Posted: Tue Jun 17, 2014 6:01 pm
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

Re: Inconsistent regular expression behavior with Find/Repla

Posted: Tue Jun 17, 2014 9:06 pm
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

Re: Inconsistent regular expression behavior with Find/Repla

Posted: Wed Jun 18, 2014 1:29 pm
by Frank Ralf
Hi Adrian,

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

Kind regards,
Frank

Re: Inconsistent regular expression behavior with Find/Repla

Posted: Wed Jun 18, 2014 6:23 pm
by Frank Ralf
(?s) works like a charm and helps tremendously!

Many thanks again for your help,
Frank