Frage

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.

War es hilfreich?

Lösung

Use regex="(\++)" to make sure the full string forms the group.

Andere Tipps

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:

([+]+)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top