Page 1 of 1

Regular Expression for Adding an Alt Tag

Posted: Thu Jun 13, 2019 7:38 am
by jmorales
I'd like to use the Find/Replace in Files feature to add an <alt> tag to images that lack it. For example, change
<image deliveryTarget="pdf" href="../graphics/g_c_cda___cda_viewer_permissions_5_9_1.png" id="135356"/>
into
<image deliveryTarget="pdf" href="../graphics/g_c_cda___cda_viewer_permissions_5_9_1.png" id="135356"><alt/></image>

I think this could be done using the Regular Expressions option of Find/Replace, but implementations of Regular Expressions seem to vary a bit. I think I need something like named or numbered backreferences (https://www.regular-expressions.info/re ... ckref.html). Does Oxygen support capturing part of the text in the target and reusing it as part of the replacement value? I'm think of something like this:

Find
<image(capture everything here)/>
Replace
<image(previously captured text)><alt/></image>

Thanks for any suggestions!

Re: Regular Expression for Adding an Alt Tag

Posted: Thu Jun 13, 2019 5:13 pm
by adrian
Hi,

Oxygen supports Java regular expression syntax in the Find/Replace tools.

You can use $n to refer numbered capturing groups (where n is a number from 1-9). $0 refers the entire search match.

Search for:
<image (.*)/>
Replace with:
<image $1><alt/></image>

.* will capture anything, so you might want to use a more specific pattern

Regards,
Adrian

Re: Regular Expression for Adding an Alt Tag

Posted: Fri Jun 14, 2019 6:17 am
by jmorales
Thanks Adrian, that worked perfectly!