Regular expression does not work in pattern facet?

Discussion in 'XML' started by Johann Sijpkes, Jul 13, 2004.

  1. Hi,
    Just before going mad I thought asking this newsgroup would be a good idea.
    I want to validate dates using a schema but somehow the regexp is not
    performed by the validator?
    (at w3c..).
    I have a small regular expression which works fine, but the long beast just
    validates. Also on invalid dates like 35/07/04 (dd/mm/yy). Anyway, in the
    online regexp tester it works fine ?
    I have no idea why this is..
    Is the expression too long? If so, is there a workaround?

    Thanks,
    Johann

    This is the code:

    <xsd:simpleType name="date_type" >
    <xsd:restriction base="xsd:string">
    <xsd:minLength value="8" />
    <xsd:maxLength value="8" />
    <xsd:pattern value="^\d{2,2}/\d{2,2}/\d{2,2}$" /> <!-- This regexp
    works, the next does not -->

    <xsd:pattern value=
    "^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/(\d{2}))|((0[1-9]|[12]\d|30)\/(
    0[13456789]|1[012])\/(\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/(\d{2}))|(29\/02\/((
    0[48]|[2468][048]|[13579][26])|(00))))$" />
    </xsd:restriction>
    </xsd:simpleType>

    <!-- Credits for the regular expression go to Dany Lauener who posted this
    on the regexp library
    http://www.regexlib.com/REDetails.aspx?regexp_id=488

    Regular expressions can be tested at :
    http://www.regexlib.com/RETester.aspx
     
    Johann Sijpkes, Jul 13, 2004
    #1
    1. Advertising

  2. "Johann Sijpkes" <> writes:

    > I have a small regular expression which works fine, but the long beast just
    > validates. Also on invalid dates like 35/07/04 (dd/mm/yy).
    >
    > This is the code:
    >
    > <xsd:simpleType name="date_type" >
    > <xsd:restriction base="xsd:string">
    > <xsd:minLength value="8" />
    > <xsd:maxLength value="8" />
    > <xsd:pattern value="^\d{2,2}/\d{2,2}/\d{2,2}$" /> <!-- This regexp
    > works, the next does not -->
    >
    > <xsd:pattern value=
    > "^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/(\d{2}))|((0[1-9]|[12]\d|30)\/(
    > 0[13456789]|1[012])\/(\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/(\d{2}))|(29\/02\/((
    > 0[48]|[2468][048]|[13579][26])|(00))))$" />
    > </xsd:restriction>
    > </xsd:simpleType>


    Apologies for your difficulties -- XSV uses Python's builtin regexp
    library, which only supports a subset of full Unicode/XML Schema
    regexps. So XSV tries to check before using the pattern that it will
    compile OK, and it rejects \ escapes python doesn't support. Which
    includes \/. This is my bug, but it won't get fixed for a while . . .

    But \/ is not needed for your pattern to work, so just
    change all \/ to / in your pattern, and it will be fine.

    ht
    --
    Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
    Half-time member of W3C Team
    2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
    Fax: (44) 131 650-4587, e-mail:
    URL: http://www.ltg.ed.ac.uk/~ht/
    [mail really from me _always_ has this .sig -- mail without it is forged spam]
     
    Henry S. Thompson, Jul 14, 2004
    #2
    1. Advertising

  3. Thanks Henry!
    The proposed solution indeed resolved the issue!


    > library, which only supports a subset of full Unicode/XML Schema
    > regexps. So XSV tries to check before using the pattern that it will
    > compile OK, and it rejects \ escapes python doesn't support. Which
    > includes \/. This is my bug, but it won't get fixed for a while . . .
    >
    > But \/ is not needed for your pattern to work, so just
    > change all \/ to / in your pattern, and it will be fine.
    >
    > ht
    > --
    > Henry S. Thompson, HCRC Language Technology Group, University of

    Edinburgh
    > Half-time member of W3C Team
    > 2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
    > Fax: (44) 131 650-4587, e-mail:
    > URL: http://www.ltg.ed.ac.uk/~ht/
    > [mail really from me _always_ has this .sig -- mail without it is forged

    spam]
     
    Johann Sijpkes, Jul 14, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,305
  2. FC
    Replies:
    4
    Views:
    5,854
    Keith Davies
    Oct 27, 2003
  3. Replies:
    1
    Views:
    452
  4. Virtual Buddha
    Replies:
    3
    Views:
    350
    Virtual Buddha
    Jun 27, 2009
  5. Stefan Rupp
    Replies:
    1
    Views:
    84
    Stefan Rupp
    Sep 20, 2003
Loading...

Share This Page