Updating MySQL rows using REGeXP?

Discussion in 'MySQL' started by tdd1984, Apr 20, 2008.

  1. #1
    I have a question, I'm trying to update all rows in our database that have domains like this http://yahoo.com I want to add www. after the http:// for example all my domains should say http://www.domainname.com I'm trying to update the ones that are missing the www. before the host name.

    Any one know the sql for this?
     
    tdd1984, Apr 20, 2008 IP
  2. beth_1977

    beth_1977 Guest

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could do it in two steps using REPLACE().

    First, do
    SET domains = REPLACE(domains,'http://','http://www.') to make sure that all of them start with at least one www (but check if you need to escape out any of the special characters - I can't remember).
    Then filter out the ones that already had one with
    SET domains = REPLACE(domains,'http://www.www.','http://www.')
     
    beth_1977, Apr 29, 2008 IP