Jump to content

[SOLVED] Update RegEx in MySql


MadTechie

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.