Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression, pattern matching in xsd

Tags:

regex

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: /^[^*+]+$/

like image 420
user459811 Avatar asked Jul 25 '11 16:07

user459811


People also ask

Does XML support regex?

You can define regular expressions for input validation in separate XML files. Reference to these regular expressions can be used in multiple data types that are defined in the datatypes. xml file.

What does '$' mean in regex?

$ means "Match the end of the string" (the position after the last character in the string).


1 Answers

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 +.

like image 113
Alan Moore Avatar answered Sep 23 '22 15:09

Alan Moore