Use regex="(\++)"
to make sure the full string forms the group.
string-length() of regex-group XSLT 2.0
-
25-06-2023 - |
質問
I have a file which contains a text like this
text +++ text ++ text + text
I want to substitute +++ with an element which takes into account the number of + for each group. I have used this xslt
...
<xsl:analyze-string select="." regex="(\+)+">
<xsl:matching-substring>
<gap reason="illegible" quantity="{string-length(regex-group(1))}" unit="character"/>
</xsl:matching-substring>
</xsl:analyze-string>
...
my desidered result is
text <gap reason="illegible" quantity="3" unit="character"/> text <gap
reason="illegible" quantity="2" unit="character"/> text <gap
reason="illegible" quantity="1" unit="character"/> text
but apparently my regex matches always only one and I get this:
text <gap reason="illegible" quantity="1" unit="character"/> text <gap
reason="illegible" quantity="1" unit="character"/> text <gap
reason="illegible" quantity="1" unit="character"/> text
Thanks a lot for any suggestion.
解決
他のヒント
Your regex usually works for matching consecutive +
character nicely. But you are only picking the one character in the group ()
. That's why you are always getting quantity="1"
is matched.
So change your regex into this one:
([+]+)
所属していません StackOverflow