Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts

    regex, invalid character range '\'

    OK
    Code:
    select '(NH4)SO4' REGEXP '^[A-Z0-9=\-]+$'
    Invalid character range
    Code:
    select '(NH4)SO4' REGEXP '^[A-Z0-9=\-()]+$'
    select '(NH4)SO4' REGEXP '^[A-Z0-9=\-\(\)]+$'
    How to solve that ?
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,550
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    MySQL is stupid.

    It doesn't allow the - in a [...] set of characters *EXCEPT* as the last character in the set.

    Code:
    select '(NH4)SO4' REGEXP '^[A-Z0-9=\(\)\-]+$'
    works fine.

    But so does simply
    Code:
    select '(NH4)SO4' REGEXP '^[A-Z0-9=()-]+$'
    In other words, the \- and - are seen as the same thing in that context.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    BubikolRamios (10-09-2011)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •