我需要获取每个'/'的值,但由于文件中包含特殊字符,我无法获得正确的输出。我如何使用正确的正则表达式来检查?我正在使用<xsl:analyze-string>
元素来获取值。这里是我的示例文件:如何使用正确的正则表达式
INPUTFILE:
<Communication>
<DialNumber>Phone/+31-3424-27385/null/Phone/+06-32-7890-565/Mobile(Office)/null/+313-(424)-28500/Fax</DialNumber>
</Communication>
预期输出
<Communication>
<ChannelCode>Phone</ChannelCode>
<UseCode>null</UseCode>
<DialNumber>+31-3424-27385</DialNumber>
</Communication>
<Communication>
<ChannelCode>Phone</ChannelCode>
<UseCode>Mobile(Office)</UseCode>
<DialNumber>+06-32-7890-565</DialNumber>
</Communication>
<Communication>
<ChannelCode>null</ChannelCode>
<UseCode>Fax</UseCode>
<DialNumber>+313-(424)-28500</DialNumber>
</Communication>
XSLTCode
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="DialNumber">
<xsl:analyze-string select="normalize-space()" regex="(\w+)/(\w+)/(\w+)">
<xsl:matching-substring>
<Communication>
<ChannelCode>
<xsl:value-of select="regex-group(1)"/>
</ChannelCode>
<UseCode>
<xsl:value-of select="regex-group(3)"/>
</UseCode>
<DialNumber>
<xsl:value-of select="regex-group(2)"/>
</DialNumber>
</Communication>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
我需要检查'/'后面的第3个单词以及后面的3个单词,最后3个单词。它看起来像这样:
Phone/+31-3424-27385/null
Phone/+06-32-7890-565/Mobile(Office)
null/+313-(424)-28500/Fax
首届正则表达式,我需要在<Channel>
分配,在<DialNumber>
第二和第三的<UseCode>
。
非常感谢您的反馈。
感谢您的反馈。 – user7918368