开发者

XSD regex failed validate: Unexpected meta character

This snippet

<xsd:element name="HomePhone" minOccurs="0">
    <xsd:simpleType>
            <xsd:restriction base="xsd:string">
                <xsd:pa开发者_运维百科ttern value="^+[0-9]{1,2}-[0-9]{1,2}-[0-9]{3}[0-9]{0,1}-[0-9]{3}[0-9]{0,1}$"></xsd:pattern>
            </xsd:restriction>
    </xsd:simpleType>
</xsd:element>

is returning the error

XSD: The regular expression '^+[0-9]{1,2}-[0-9]{1,2}-[0-9]{3}[0-9]{0,1}-[0-9]{3}[0-9]{0,1}$' failed to validate at location 1: Unexpected meta character.

Any idea what is wrong?

Thanks in advance


In the XML Schema regex flavor, all matches are implicitly anchored at both ends, so you don't need to add the ^ and $. According to the spec, those two characters are supposed to be treated as literal text. But if it that were the case, the ^+ in your regex would try to match one or more ^ characters, not throw an exception.

I suspect they're being treated as anchors despite the spec. And it makes no sense to match an anchor more than once, so the + is treated as an error. Come to think of it, it makes no sense to have a quantifier in that position in any case; what was the + supposed to do? Anyway, your regex should work if you delete that character.


^     Start of line
+     preceding character one or more times

There is no 'preceding character'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜