Page 1 of 1

regex not selecting last end of line

Posted: Thu Dec 07, 2023 7:30 pm
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.

Re: regex not selecting last end of line

Posted: Fri Dec 08, 2023 12:22 pm
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.

Re: regex not selecting last end of line

Posted: Thu Aug 01, 2024 1:06 pm
by EmmaAlva
To delete the first three lines of your XML code using a regex, you can use a regex that matches the lines and includes the newline characters at the end tiny fishing
Here's a refined regex that should work for you:
<row>\s*<entry namest="col1" nameend="col2"\s*/>\s*</row>\s*
This regex will match the entire block including the newline characters. If you are using a programming language or a tool that supports multi-line regex, ensure you have the multi-line mode enabled.