MySQL Forums
Forum List  »  Newbie

Re: Is "Ereg replace" possible ?
Posted by: Felix Geerinckx
Date: August 09, 2005 01:52AM

atmaweapon wrote:

> I'd like to make a "query replace" using regular expression in my records... Is it possible ?
> Something like this :
> UPDATE my_table SET myField="\1bar\2" WHERE myField="(.*)foo(.*)";
>
> I don't know if MySQL even permit this

MySQL regular expressions do not have this kind of functionality . They are match-only at present, returning either 1 (match) or 0 (no match).

However, depending on the complexity of your data, you might be able to use something like:

SET @a:= 'this is textfooand this is more text';
SELECT
SUBSTRING(@a, 1, INSTR(@a, 'foo')-1) AS '1',
SUBSTRING(@a, INSTR(@a, 'foo') + LENGTH('foo')) AS '2';

--
felix
Please use BBCode to format your messages in this forum.

Options: ReplyQuote


Subject
Written By
Posted
August 06, 2005 07:15AM
Re: Is "Ereg replace" possible ?
August 09, 2005 01:52AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.