Page 1 of 1
Reg exp for appending file extension
Posted: Fri Dec 16, 2022 5:34 pm
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.
Re: Reg exp for appending file extension
Posted: Fri Dec 16, 2022 6:10 pm
by mike004
I think I need to use brackets to specify the capture group.
Find: "(.*)"
Replace With: "$1.dita"
Re: Reg exp for appending file extension
Posted: Mon Dec 19, 2022 11:46 am
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
Re: Reg exp for appending file extension
Posted: Fri Dec 23, 2022 5:53 pm
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!
Re: Reg exp for appending file extension
Posted: Wed May 17, 2023 11:42 am
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
Re: Reg exp for appending file extension
Posted: Fri May 19, 2023 12:59 pm
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.