regex not selecting last end of line

Questions about XML that are not covered by the other forums should go here.
amjc
Posts: 3
Joined: Fri Mar 31, 2023 3:18 pm

regex not selecting last end of line

Post by amjc »

Hi, I want to delete (i.e. replace wiith nothing) the first three lines of this code
<row>
<entry namest="col1" nameend="col2"/>
</row>
<row>
and when I use this regex
<row>$\s*<entry namest="col1" nameend="col2"\/>$\s*<\/row>$\s
It doesn't select the final eol, so it ends up replacing the 3 unwanted lines with a blank line.
Any suggestions? Would also be open to something using xpath.
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: regex not selecting last end of line

Post by adrian »

Hi,

I don't see a problem with the regex, it should also match the line break after the closing row tag. In Oxygen the line breaks in XML are strictly \n (a single whitespace).
You may want to also add ^\s* in front, so that it consumes the indent in front of the row start tag. Perhaps that's what you see at the end.

XPath would be: //row[entry[@namest="col1" and @nameend="col2"]]
But note that in case of XPath moreso you can't remove the trailing line break as it is outside of the row tags.
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply