Regular Expression for Adding an Alt Tag
Oxygen general issues.
-
- Posts: 93
- Joined: Tue Oct 30, 2018 9:47 pm
Regular Expression for Adding an Alt Tag
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!
<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!
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Regular Expression for Adding an Alt Tag
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
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
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service