【发布时间】:2018-10-20 14:06:31
【问题描述】:
我需要匹配一个字符串的确切长度,我正在使用下面的代码:
declare namespace
ns123='urn:lt:sb:xmlns:services:customers:customerinformationfile:GetCustByGlobalId:1.2';
matches(//ns123:legalCode, "[0-9-]{10}")
问题是它只适用于更大的长度(例如,如果字段内容为 11,则失败,但如果内容为 9,则不会)。
【问题讨论】:
-
如果您想检查字符串长度,您不应该使用正则表达式,只需尝试内置 XPath 方法,例如
string-length(//ns123:legalCode)=10(检查长度是否正好是 10 个字符)、string-length(//ns123:legalCode)>10(超过 10 个)等...