Jump to content


Photo

Regex for selecting DB entry starting with any number...


  • Please log in to reply
3 replies to this topic

#1 kabbink

kabbink
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 21 July 2006 - 06:30 PM

Hello all,

Sorry I am a total regexp noob and my question will probably take any one of you only a few seconds.  Im sure it has been asked before but I tried searching and couldnt find it.  This might be a good one to add to the "Common Expressions" thread.

Anyway all I am trying to do is select from a MySQL database any entry that starts with any number....

My query will look like this
$sql = "SELECT * FROM members WHERE company LIKE 'regexp' ORDER BY company";

Thanks for the help on this mundane questions...
Kevin

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 21 July 2006 - 06:38 PM

MySQL has a REGEXP operator for this. Try SELECT field REGEXP '^[0-9]'.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 kabbink

kabbink
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 21 July 2006 - 07:10 PM

Hello and thanks for the reply...

So do I need to do something like this:

SELECT * FROM members WHERE company LIKE '^[0-9]%'

I need to select everything from my members database where the company field begins with a number.

The above query yields no results so obviously I am doing something wrong...

Sorry for not understanding your first answer.
Kevin

#4 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 21 July 2006 - 07:33 PM

Look here. SELECT * FROM members WHERE company REGEXP '^[0-9]'
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users