SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    update records based on regex

    I need to update some records using a regex and others trigger them just if they are empty, when they are empty I have no problems but when it is a regular expression I always get an empty result but and I can't figure out how to

    The fields look like this

    Code:
    [caption id="" align="alignright" width="180" caption=""]<a href="http://www.medialifemagazine.com/archives/images/collegebag.gif"><img class="size-full" title="collegebag.gif" src="http://www.medialifemagazine.com/archives/images/collegebag.gif" alt="" width="180" height="259" /></a>[/caption]

    and this is my regex

    Code MySQL:
    ^\[caption +[a-zA-Z=" 0-9\]<>:/.-]*\[\/caption\]$

    Can someone help me out?
    Do you get bothered because I do the same thing every day?
    Do you question why I do it?
    Then find something that you actually like doing!!!

    Stop thinking on what I do.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,263
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by tlacaelelrl View Post
    I need to update some records using a regex ...
    are you asking for a php solution or a mysql solution?

    because mysql REGEXP can only find, not replace
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    no, a MySQL, I guess I was doing it wrong, I now have a regex that works

    [^[caption .+[/caption]]

    that does find matches but I want to make sure it ends right after [/caption] but when I add $ it does not find anything

    I know MySQL does not do search replace but I will be doing something like

    UPDATE `wp_posts` SET `post_content`=`post_content` + `someothefiled` WHERE `post_content` = [^[caption .+[/caption]]

    I also have to read on this, I think it should be done with CONCAT but first I want to get the regex working
    Do you get bothered because I do the same thing every day?
    Do you question why I do it?
    Then find something that you actually like doing!!!

    Stop thinking on what I do.

  4. #4
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Okay, I think I have the concat I just need to make sure the regex works and does not modify records I don't want it to, I will be doing something like this


    UPDATE `wp_posts` SET `post_content`= concat(`post_content`,`post_excerpt`) WHERE `post_content` REGEXP '[^[caption .+[/caption]$]'
    Do you get bothered because I do the same thing every day?
    Do you question why I do it?
    Then find something that you actually like doing!!!

    Stop thinking on what I do.


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
  •