Look-around and multi-line support in Find/Replace

Are you missing a feature? Request its implementation here.
solarian
Posts: 48
Joined: Thu Mar 12, 2009 10:27 pm

Look-around and multi-line support in Find/Replace

Post by solarian »

I know these are both already on the enhancement list, but I'd like to draw attention to these two for support in Find/Replace with regular expressions.

Firstly, Perl "look-around" assertions currently work alright with Find, but produce an error if one tries to replace the found text with anything.

Secondly, multi-line support (i.e., the regex 's' pattern modifier) is lacking in Find/Replace with regex, which is pretty crucial when OxygenXML's formatting of XML adds lots of newlines. The only way to deal with this is to remove all newlines from a document before doing Find/Replace, which isn't a massive problem but it is an inconvenience. Given that OxygenXML treats \x0A as whitespace by default, the default for Find/Replace should be with the 's' modifier IMHO, otherwise a pattern that matches before using Format/Indent will stop working afterwards, which isn't terribly helpful.

Otherwise OK :-)
solarian
Posts: 48
Joined: Thu Mar 12, 2009 10:27 pm

Re: Look-around and multi-line support in Find/Replace

Post by solarian »

P.S. Obviously, removing newlines in a long document causes a massive performance hit, so actually it can be a problem.
Radu
Posts: 9051
Joined: Fri Jul 09, 2004 5:18 pm

Re: Look-around and multi-line support in Find/Replace

Post by Radu »

Hello,

The "look-around" issues have been addressed and the fix should be available in the next minor version(10.3).

As for the multi-line support can you give us an example of a use case?

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
solarian
Posts: 48
Joined: Thu Mar 12, 2009 10:27 pm

Re: Look-around and multi-line support in Find/Replace

Post by solarian »

Thanks for the previous fix.

As an example of the multi-line issue, consider this preformatted XML fragment:

Code: Select all


<p>This is a sample paragraph<note>ety. <foreign
xml:lang="grc">παραγραφη</foreign>
</note> in an imaginary document.</p>
If we wanted to find the <note> element we might use this:

Code: Select all

<note>(.*?)</note>
but it would fail because of the line breaks, which aren't included in the definition of the '.' meta-character unless one sets the 's' pattern modifier. Obviously, this is a problem if you want to keep your XML pretty with lots of line breaks.

For comparison, the regex would work on this reformatted, but equivalent, XML:

Code: Select all


<p>This is a sample paragraph<note>ety. <foreign xml:lang="grc">παραγραφη</foreign></note> in an imaginary document.</p>
The fact that Perl (and presumably Java) defaults to the above behaviour is rather inappropriate for XML, where line breaks aren't treated differently from other whitespace, and particularly inappropriate in OxygenXML where line breaks are essential for performance reasons.
Radu
Posts: 9051
Joined: Fri Jul 09, 2004 5:18 pm

Re: Look-around and multi-line support in Find/Replace

Post by Radu »

Hello,

We will consider adding an option which will allow '.' to also match line breaks however this most probably will not be the default behavior.
The reason is, in some cases, you may want to preserve the white spaces(space="preserve") and this feature would interfere and probably lead to unwanted results.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
solarian
Posts: 48
Joined: Thu Mar 12, 2009 10:27 pm

Re: Look-around and multi-line support in Find/Replace

Post by solarian »

Hi,

I understand your reluctance to change the default behaviour; but with respect to adding an option to allow '.' to match line breaks, I think this is an essential part of regex support.

Best wishes,

Ian
tavy
Posts: 365
Joined: Thu Jul 01, 2004 12:29 pm

Re: Look-around and multi-line support in Find/Replace

Post by tavy »

Hello Ian,

An option to allow '.' to also match line terminators has been added('Dot matches all') and will be available starting with the next minor version of <oXygen/> XML Editor (v11.1).

Best Regards,
Octavian Nadolu
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
solarian
Posts: 48
Joined: Thu Mar 12, 2009 10:27 pm

Re: Look-around and multi-line support in Find/Replace

Post by solarian »

:)
Post Reply