Regular Expression for Adding an Alt Tag

Oxygen general issues.
jmorales
Posts: 93
Joined: Tue Oct 30, 2018 9:47 pm

Regular Expression for Adding an Alt Tag

Post 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!
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Regular Expression for Adding an Alt Tag

Post 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
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
jmorales
Posts: 93
Joined: Tue Oct 30, 2018 9:47 pm

Re: Regular Expression for Adding an Alt Tag

Post by jmorales »

Thanks Adrian, that worked perfectly!
Post Reply