Jump to content

Recommended Posts

Not sure if it can be done, but i thought i'll check..

 

OK RegEx can be used with SELECT Statments on MySQL but Can i use it to UPDATE (something like PREG_REPLACE) i have searched around and don't think its supported but i am not 100% sure..

 

OK my System Config:

PHP Version 5.2.1

MySQL Client API version 4.1.22

posix

Revision $Revision: 1.70.2.3.2.12 $

 

 

If anymore System Info is needed just ask..

 

any info will help

 

Thanks in advance

 

--MadTechie

Link to comment
https://forums.phpfreaks.com/topic/48351-solved-update-regex-in-mysql/
Share on other sites

It works for me (v5.0.38).

 

UPDATE my_table SET firstname='David' WHERE lastname RLIKE 'ingston$';

 

Oh, wait a minute.  Like preg_REPLACE?  So you want to capture a parenthetical subpattern and use that in the SET value?  Oh.  No.  Probably not.

 

There's a replace() function, but it hardly has the power of regex.

 

If it's a one-time/infrequent thing, you could write a PHP (or other) script to suck out the data, submit it to a preg_replace, and spit it back in.  Otherwise, that wouldn't be efficient to do on a large set of data all the time.

yeah i started a script to do that..

i have tried to shorten the process using REGEXP but even then my more compleax RegEx don't seam to work well.. probably just a bad day. will try in the morning.

 

Thanx for all your help Wildbug

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.