SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    preg_match in MySQL

    Hi Guys!

    I need a way to perform a preg_match within MySQL. For example:

    PHP Code:
    preg_match('~[0-9]~'"mydomain.com"
    Whats the best way?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,273
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    if you would kindly explain what those special characters do, then i'll give it a try

    mysql has regular expressions (see REGEXP in da manual) but the tilde (~) is not included
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    if you would kindly explain what those special characters do, then i'll give it a try

    mysql has regular expressions (see REGEXP in da manual) but the tilde (~) is not included
    The preg_match I posted above basically searches the string for any numbers and returns true if it finds any.

    Basically I have created a search form in PHP and the user has the ability to select "Exclude hyphens" and "Exclude numbers" from search options. When they select Exlude hyphens for example, the search should return only rows that DO NOT contain hyphens. The same applies for numbers.

    I am trying something like this, but to no avail:

    PHP Code:
    select from domains where domain NOT LIKE '^[0-9]+$' 

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,273
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    returns true if any numbers are found...
    Code:
    WHERE domain REGEXP '[[:digit:]]'
    alternatively...
    Code:
    WHERE domain REGEXP '[0-9]'
    returns true if any hyphens are found...
    Code:
    WHERE domain REGEXP '-'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great, works fine - thank you


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
  •