Reputation: 834
I've the below XML String
<para><content-style font-style="bold">59/App/1/1 Amendment—</content-style>
</para>
and the below regex match.
<xsl:template match="para[fn:not(@align)]/content-style[1]/text()">
<xsl:choose>
<xsl:when test="fn:not(contains(substring-before(.,'/'),' '))">
<xsl:analyze-string select="." regex="([0-9]+[\w+]?)/([0-9]+[\w+]?)/([0-9]+[\w+]?)/([0-9]+[\w+]?)">
<xsl:matching-substring>
<span class="phrase">
<a name="{concat('P',regex-group(1),'-',regex-group(2),'-',regex-group(3),regex-group(4))}"/>
<xsl:value-of select="."></xsl:value-of>
</span>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:analyze-string select="." regex="([0-9]+[\w+]?)/([0-9]+[\w+]?)/([0-9]+[\w+]?)">
<xsl:matching-substring>
<span class="phrase">
<a name="{concat('P',regex-group(1),'-',regex-group(2),'-',regex-group(3))}"/>
<xsl:value-of select="."></xsl:value-of>
</span>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:analyze-string select="." regex="([0-9]+[\w+]?)/([0-9]+[\w+]?)">
<xsl:matching-substring>
<span class="phrase">
<a name="{concat('P',regex-group(1),'-',regex-group(2))}"/>
<xsl:value-of select="."></xsl:value-of>
</span>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."></xsl:value-of>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
here i want to match 59/App/1/1
with regex, but i'm unable to understand how to do it.
I tried to analyze-string
using <xsl:analyze-string select="." regex="([0-9]+[\w+]?)/([0-9]+[\w+]?)/([0-9]+[\w+]?)/([0-9]+[\w+]?)">
, and it is not getting matched., please let me know where i went wrong and how to fix this.
Thanks
Upvotes: 0
Views: 4249
Reputation: 80629
In your pattern:
([0-9]+[\w+]?)
[0-9]+
matches a single character present in the range between 0 and 9, as many times as possible[\w+]?
matches a single character from +
and [A-Za-z0-9_]
character set, zero and one time.Since this pattern will never match the word App
; your regex fails.
You can use the following pattern:
(\w+)/(\w+)/(\w+)/(\w+)
as \w
already includes the [0-9]
class.
Upvotes: 2