【问题标题】:SoapUI Xpath assertion: match the exact length of the fieldSoapUI Xpath 断言:匹配字段的确切长度
【发布时间】: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 个)等...

标签: xpath soapui assertion


【解决方案1】:

你快到了。您只需要在您的正则表达式中设置一些开始和结束边界:

^[0-9-]{10}$

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-15
    • 1970-01-01
    • 2018-09-25
    相关资源
    最近更新 更多