Need workaround for lookarounds in XPATH regex
Questions about XML that are not covered by the other forums should go here.
Need workaround for lookarounds in XPATH regex
Hi,
it seems, that the <sqf:stringReplace/> regular expressions (in XSLT/Schematron) do not support lookarounds. I need to find a solution for matching words, that are not part of another string. Without lookarounds (e.g. foo(?=\s)), this seems to get very ugly.
e.g., when trying to match 'foo', this should match:
but this should not match, because 'foo' is a substring of 'foobar'.
I workaround this by also matching the preceding and following chars. But this is really dirty, but I cannot find a better solution. Do you have an implementation idea for me?
it seems, that the <sqf:stringReplace/> regular expressions (in XSLT/Schematron) do not support lookarounds. I need to find a solution for matching words, that are not part of another string. Without lookarounds (e.g. foo(?=\s)), this seems to get very ugly.
e.g., when trying to match 'foo', this should match:
Code: Select all
lorem ipsum foo bar.
Code: Select all
lorem ipsum foobar.
<sqf:fix id="replace-foo">
<sqf:description>
<sqf:title>Replace 'foo' with an allowed term: 'bar'</sqf:title>
</sqf:description>
<sqf:stringReplace regex="(\sfoo$)" select="' bar'"/>
<sqf:stringReplace regex="(^foo\s)" select="'bar '"/>
<sqf:stringReplace regex="(^foo$)" select="'bar'"/>
<sqf:stringReplace regex="(\sfoo\s)" select="' bar '"/>
<sqf:stringReplace regex="(\sfoo\.)|(^foo\.)" select="'bar.'"/>
<sqf:stringReplace regex="(\sfoo\?)|(^foo\?)" select="'bar?'"/>
<sqf:stringReplace regex="(\sfoo\!)|(^foo\!)" select="'bar!'"/>
<sqf:stringReplace regex="(\sfoo\;)|(^foo\;)" select="'bar;'"/>
<sqf:stringReplace regex="(\sFoo$)" select="' Bar'"/>
<sqf:stringReplace regex="(^Foo\s)" select="'Bar '"/>
<sqf:stringReplace regex="(^Foo$)" select="'Bar'"/>
<sqf:stringReplace regex="(\sFoo\s)" select="' Bar '"/>
<sqf:stringReplace regex="(\sFoo\.)|(^Foo\.)" select="'Bar.'"/>
<sqf:stringReplace regex="(\sFoo\?)|(^Foo\?)" select="'Bar?'"/>
<sqf:stringReplace regex="(\sFoo\!)|(^Foo\!)" select="'Bar!'"/>
<sqf:stringReplace regex="(\sFoo\;)|(^Foo\;)" select="'Bar;'"/>
</sqf:fix>
stefan-jung.org – Your DITA/DITA-OT XML consultant
Re: Need workaround for lookarounds in XPATH regex
Hello,
In <oXygen/> XML Editor 18.1 we updated the sqf:stringReplace operation to allow using Java regular expressions. The Saxon "j" flag is automatically set for the regular expressions of the sqf:stringReplace operation.
You can read more about this in our user manual: https://www.oxygenxml.com/doc/versions/ ... tions.html
This will allow you to use "\b" in a regular expression to match word boundaries.
So you can create a quick fix something like this:
Best Regards,
Octavian
In <oXygen/> XML Editor 18.1 we updated the sqf:stringReplace operation to allow using Java regular expressions. The Saxon "j" flag is automatically set for the regular expressions of the sqf:stringReplace operation.
You can read more about this in our user manual: https://www.oxygenxml.com/doc/versions/ ... tions.html
This will allow you to use "\b" in a regular expression to match word boundaries.
So you can create a quick fix something like this:
Code: Select all
<sqf:fix id="replace-foo">
<sqf:description>
<sqf:title>Replace 'foo' with an allowed term: 'bar'</sqf:title>
</sqf:description>
<sqf:stringReplace regex="\b(foo)\b" select="'bar'"/>
<sqf:stringReplace regex="\b(Foo)\b" select="'Bar'"/>
</sqf:fix>
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “General XML Questions”
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