SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    Montreal
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Searching for data starting by a numeric value

    Hi,

    I've got a huge listing of name and to quickly search for a specific letter, I have a A to Z list of link.

    But as some name started by a numeric value, I have create a # link but I am wondering how can I do a SEARCH for all numeric value (0-9) in the appropriate way (I mean not doing field LIKE '0%' OR .....).

    So it there a way to search for all name starting with a numeric value easely in MySQL (with regular expression maybe???)

    Thank for any help!!!

  2. #2
    Non-Member adstiger's Avatar
    Join Date
    Nov 2008
    Location
    Canada
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The basic syntax to use regular expressions in a MySQL query is:

    SELECT something FROM table WHERE column REGEXP 'regexp'

    For example, to select all columns from the table events where the values in the column id end with 5587, use:

    SELECT * FROM events WHERE id REGEXP '5587$'

    A more elaborate example selects all columns of the table reviews where the values in the column description contain the word excellent:

    SELECT * FROM reviews WHERE description REGEXP '[[:]]excellent[[:>:]]’

    MySQL allows the following regular expression metacharacters:

    . match any character
    ? match zero or one
    * match zero or more
    + match one or more
    {n} match n times
    {m,n} match m through n times
    {n,} match n or more times
    ^ beginning of line
    $ end of line
    [[:]] match beginning of words
    [[:>:]] match ending of words
    [:class:] match a character class
    i.e., [:alpha:] for letters
    [:space:] for whitespace
    [unct:] for punctuation
    [:upper:] for upper case letters
    [abc] match one of enclosed chars
    [^xyz] match any char not enclosed
    | separates alternatives

    MySQL interprets a backslash (\) character as an escape character. To use a backslash in a regular expression, you must escape it with another backslash (\\).

  3. #3
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    Montreal
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank alot adstiger, this list will be very useful

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not just post the link to the website which wrote all that?
    http://www.tech-recipes.com/rx/484/u...ct-statements/

  5. #5
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    Montreal
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice site crmalibu .... now in my bookmarks!


Bookmarks

Posting Permissions

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