kabbink Posted July 21, 2006 Share Posted July 21, 2006 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 '[b]regexp[/b]' ORDER BY company";Thanks for the help on this mundane questions...Kevin Link to comment https://forums.phpfreaks.com/topic/15283-regex-for-selecting-db-entry-starting-with-any-number/ Share on other sites More sharing options...
effigy Posted July 21, 2006 Share Posted July 21, 2006 MySQL has a [url=http://dev.mysql.com/doc/refman/5.0/en/regexp.html]REGEXP[/url] operator for this. Try [tt]SELECT field REGEXP '^[0-9]'[/tt]. Link to comment https://forums.phpfreaks.com/topic/15283-regex-for-selecting-db-entry-starting-with-any-number/#findComment-61775 Share on other sites More sharing options...
kabbink Posted July 21, 2006 Author Share Posted July 21, 2006 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 [i]begins[/i] with a number.The above query yields no results so obviously I am doing something wrong...Sorry for not understanding your first answer.Kevin Link to comment https://forums.phpfreaks.com/topic/15283-regex-for-selecting-db-entry-starting-with-any-number/#findComment-61790 Share on other sites More sharing options...
effigy Posted July 21, 2006 Share Posted July 21, 2006 Look [url=http://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html]here[/url]. [tt]SELECT * FROM members WHERE company REGEXP '^[0-9]'[/tt] Link to comment https://forums.phpfreaks.com/topic/15283-regex-for-selecting-db-entry-starting-with-any-number/#findComment-61806 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.