SQL replace regexp?

UPDATE `test`
SET `name` = REPLACE(`name`, REGEXP '[A-Za-z], [A-Za-z]', '')

How to use REGEXP in replace query?

can’t… all REGEXP can do is “yes or no” whether the string matches the pattern

if you are stuck it would be very ugly but you could do a query to find all of the records with a comma and a space and then loop through the results. Then using php you can look for the pattern and do an update query if it finds it.

Not the most elegant but you can see what is going on as you can echo out the results before adding the update query so you know it is finding what it should.

Might not be the best solution if you have 2 million records but should be fine for a couple of thousand and you could split it using Limit 0,1000 etc

Thanks guys looks too complex. It’s only 300 rows anyways gonna do it manually :slight_smile:

Thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.