Regex to match xrefs

Having trouble installing Oxygen? Got a bug to report? Post it all here.
gbv34
Posts: 105
Joined: Thu Jan 20, 2022 12:36 pm

Regex to match xrefs

Post 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 :)
You do not have the required permissions to view the files attached to this post.
------
Gaspard
Radu
Posts: 9434
Joined: Fri Jul 09, 2004 5:18 pm

Re: Regex to match xrefs

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
gbv34
Posts: 105
Joined: Thu Jan 20, 2022 12:36 pm

Re: Regex to match xrefs

Post 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
You do not have the required permissions to view the files attached to this post.
------
Gaspard
Radu
Posts: 9434
Joined: Fri Jul 09, 2004 5:18 pm

Re: Regex to match xrefs

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
gbv34
Posts: 105
Joined: Thu Jan 20, 2022 12:36 pm

Re: Regex to match xrefs

Post 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 :)
------
Gaspard
chrispitude
Posts: 922
Joined: Thu May 02, 2019 2:32 pm

Re: Regex to match xrefs

Post 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).
gbv34
Posts: 105
Joined: Thu Jan 20, 2022 12:36 pm

Re: Regex to match xrefs

Post by gbv34 »

This is an excellent tip, Chris! Thank you!
------
Gaspard
Post Reply