Page 1 of 1

Regex to match xrefs

Posted: Fri Jul 29, 2022 10:17 am
by gbv34
Hello,
I use the following grep command to find xref elements, whatever their reference filenames are.

Code: Select all

grep -ri 'xref href="[^"]\+"/>' *
This works well. However, when I want to use the expression solely in Oxygen, I don't get any results.

Code: Select all

xref href="[^"]\+"/>
image.png
Do you have any idea of the formatting or request to make it work?
Any feedback is welcome. Thanks a lot :)

Re: Regex to match xrefs

Posted: Fri Jul 29, 2022 10:45 am
by Radu
Hi,
How about if you uncheck the "Enable XML search options" checkbox? Because this checkbox splits the XML content in intervals but your search string spans both element names and attribute values, so it's not something which for example matches just inside an attribute value.

Regards,
Radu

Re: Regex to match xrefs

Posted: Fri Jul 29, 2022 11:45 am
by gbv34
Hi Radu :D
Thanks for your answer. Unselecting this option didn't help to retrieve the elements.
Even within a topic, it doesn't seem to work although I have one xref element under my eyes.
I'll continue looking if there are other options that could help.
image.png

Re: Regex to match xrefs

Posted: Fri Jul 29, 2022 11:50 am
by Radu
Hi,

This works for me in Oxygen:

Code: Select all

<xref href="[^"]+"/>
Your original attempt escaped the "\+" sign meaning that it was searched as a literal + sign.
Also why not search directly for "<xref" with or without regexp?

Regards,
Radu

Re: Regex to match xrefs

Posted: Fri Jul 29, 2022 1:11 pm
by gbv34
Problem solved!
I used this expression

Code: Select all

xref href="[^"]+.dita"\>
and I deactivated the XML search options.
Thanks for your help :)

Re: Regex to match xrefs

Posted: Fri Jul 29, 2022 1:23 pm
by chrispitude
Hi gbv34,

You might want to test that on an <xref> that wraps within the element:

Code: Select all

<xref
href="foo.dita"
/>
If that does not match, consider something like

Code: Select all

xref\s+href="[^"]+.dita"\s*\>
as there can be cases where the opening tag and even the closing bracket can be word-wrapped onto another line (although perhaps not in your DITA source, but definitely in ours).

Re: Regex to match xrefs

Posted: Fri Jul 29, 2022 2:18 pm
by gbv34
This is an excellent tip, Chris! Thank you!