Need workaround for lookarounds in XPATH regex
Posted: Wed Mar 08, 2017 2:15 pm
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>