Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

regex - Regular Expression, pattern matching in xsd

I was wondering how to make a regular expression for any character except * and + . I've tried ([^*+]) and ([^*+]) but both expressions seem to be incorrect. Can someone please point me in the right direction? Thanks.

Edit: Here is a code snipet. I've attached the reg ex suggested below into visual studio and it still generates an error when i enter in a regular string.

<xsd:element name="elementName">
    <xsd:simpleType>
        <xsd:restriction base="xsd:string">
            <xsd:pattern value="/^[^*+]+$/"></xsd:pattern>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>   

Edit: The example string I'm using is "test" The result is pattern constraint fail with the current reg ex: /^[^*+]+$/

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In the XML Schema regex flavor, you must not add regex delimiters (i.e., the / at either end of /^[^*+]+$/). You also don't need to use anchors (i.e., the ^ at the beginning and $ at the end); all regex matches are automatically anchored at both ends. That line should read:

<xsd:pattern value="[^*+]+"></xsd:pattern>

...meaning the whole element must consist of one or more of any characters except * and +.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...