List:General Discussion« Previous MessageNext Message »
From:Dan Nelson Date:November 8 2006 6:53pm
Subject:Re: Regular expression not working as expected (documented)?
View as plain text  
In the last episode (Nov 08), Leandro Guimar~aes Faria Corcete DUTRA said:
> Em Qua, 2006-11-08 às 19:16 +0100, Christian Hammers escreveu:
> > 
> > On 2006-11-08 Leandro Guimar~aes Faria Corcete DUTRA wrote:
> > >         u.login REGEXP
> '^wa[bhkl][_[.period.]-acegmnopqrsuvwxyz]{1,5}[14Lt][23890IJOQ].*'
> > ...
> > > But I get, among otherss, a string beginning with 'walt'
> > > (several, in fact).
> > 
> > Probably MySQL don't know about this "[.period.]" thing and just
> > takes the "." in it as "any char", e.g. your "t" from "walt".
> 
> 	I got that from cname.h, mentioned in the MySQL regexp documentation.
> 
> > Try '^wa[bhkl][-_acegmnopqrsuvwxyz]{1,5}[14Lt][23890IJOQ].*', if
> > there is a "-" at the beginning of a character class it is usually
> > threaten literally as it makes no sense as "from..to" separator in
> > those cases.
> 
> 	Hm, but I do need to take into account the period.

"." within brackets is treated literally anyway, so there's no need to
use "[.period.]".
 
> 	Also, do you mean the - at the beginning will make all
> following characters be treated literally?

No, but it prevents - from being parsed as a range operator. "[.-a]"
matches any character between ascii 46 and 97.  Also, since mysql uses
case-insensitive compares by default, it will match any lowercase
character (since the uppercase characters between 65 and 90 are within
your range).  That's why the "t" in "walt" was matching.  The right
syntax for your original regex would probably look like:

REGEXP BINARY '^wa[bhkl][-_.acegmnopqrsuvwxyz]{1,5}[14Lt][23890IJOQ].*'

-- 
	Dan Nelson
	dnelson@stripped
Thread
Regular expression not working as expected (documented)?Leandro Guimarães Faria Corcete DUTRA8 Nov
  • Re: Regular expression not working as expected (documented)?Christian Hammers8 Nov
    • Re: Regular expression not working as expected (documented)?Leandro Guimarães Faria Corcete DUTRA8 Nov
      • Re: Regular expression not working as expected (documented)?Dan Nelson8 Nov
        • Re: Regular expression not working as expected (documented)?Leandro Guimarães Faria Corcete DUTRA8 Nov
      • Re: Regular expression not working as expected (documented)?Christian Hammers8 Nov
    • RE: Regular expression not working as expected (documented)?Jerry Schwartz8 Nov