Reg exp for appending file extension

Questions about XML that are not covered by the other forums should go here.
mike004
Posts: 18
Joined: Fri Feb 18, 2011 2:29 pm

Reg exp for appending file extension

Post by mike004 »

Trying to change all instances of the type <xref href="myfile"> to <xref href="myfile.dita"> using Find/Replace.
If I set Xpath to //xref/@href and enter a regexp of ".*", that seems to find the required text string.
How can I then quote the found text string in the Replace With box?
\1 or $1 does not seem to work.
mike004
Posts: 18
Joined: Fri Feb 18, 2011 2:29 pm

Re: Reg exp for appending file extension

Post by mike004 »

I think I need to use brackets to specify the capture group.
Find: "(.*)"
Replace With: "$1.dita"
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Reg exp for appending file extension

Post by adrian »

Hi,

If you want to refer the entire found string, you can use \0 or $0 in the "Replace with" field.
But yes, you can also use explicit capturing groups, like you mentioned.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
chrispitude
Posts: 907
Joined: Thu May 02, 2019 2:32 pm

Re: Reg exp for appending file extension

Post by chrispitude »

Sometimes for tasks a bit more complicated than this, I create a temporary refactoring operation, run it, then delete it.

It would be useful to have something like XPath/XQuery Builder, but that would let me apply XSLT templates that are not worth creating an entire refactoring operation for:

Code: Select all

  <xsl:template match="@href[not(ends-with(., '.dita'))]">
    <xsl:attribute name="href" select=". || '.dita'"/>
  </xsl:template>
Ideally it would have scope controls and a preview functionality that could be used to fine-tune the templates, like an extra powerful find-and-replace. Just throwing the idea out there!
Radu
Posts: 9048
Joined: Fri Jul 09, 2004 5:18 pm

Re: Reg exp for appending file extension

Post by Radu »

Hi Chris,
We have an internal issue:
EXM-40404 XML refactoring custom operation which calls an XSLT specified by the end user

I think my idea there was that in the main menu Tools->"XML Refactor" dialog there would be a special refactoring action named something like "Apply XSLT" which would ask you to paste the XSLT to apply as a parameter in the dialog or to maybe add a reference to an XSLT which is somewhere on disk... and maybe to allow customizing also other parameters declared in the XSLT.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
chrispitude
Posts: 907
Joined: Thu May 02, 2019 2:32 pm

Re: Reg exp for appending file extension

Post by chrispitude »

Hi Radu,

That would work! And it would allow the operation to be previewed, which is also great.

For us, the text box would be better as our use case would be a writer applying something that I give them in an email. Novice writers might be a bit more confused by temporary files, forgetting to delete them, creating them in the Git repo directory and accidentally checking them in, etc.
Post Reply