MySQL: Mass Replace using a regex? - mysql

I'm trying to replace all instances of   with a simple space EXCEPT if it's surrounded by DIV tags. I've tried tinkering with the NOT REGEXP and NOT RLIKE within the replace query, like this:
UPDATE table SET column = replace(column,NOT REGEXP '> <',' ');
But it gives a syntax error. Anyone have any suggestions?

How about three separate updates...
UPDATE table SET column = replace(column, '> <', '%%LOL$$');
UPDATE table SET column = replace(column, ' ', ' ');
UPDATE table SET column = replace(column, '%%LOL$$', '> <');

Something like this should work:
UPDATE table SET column = REPLACE(column, ' ', ' ') WHERE column NOT LIKE '%div> </%'

Related

UPDATE tbl SET name = REGEXP_REPLACE(`name`,[:digit:],'')

I try to get rid of some digits in my table.
What is wrong with this:
UPDATE tbl SET `name` = REGEXP_REPLACE(`name`,[:digit:],'')
it won't execute showing: REGEXP_REPLACE is not valid at this position...
thanx.
You put the field between comma: 'name'. Your query is trying to REGEXP replace inside the text 'name'. Rremove the quotes to replace your field value:
UPDATE tbl SET name = REGEXP_REPLACE(name,[:digit:],'')

How to remove all instances of a specific character from a column in MySQL

I have a database on MySQL where the data in the "Name" column contains unwanted carets (^). For example, a name might be "John^ Test^^". Is there any way to remove all these characters from the column?
May be this can help.
Update
Yourtable
Set
Name = replace(name, '^', '');
You could do something like this:
UPDATE table SET column = REPLACE(myColumn, '^', ' ')

MySQL: UPDATE column WHERE column STARTS WITH " " (Blankspace)

I need to search and UPDATE my database for column values starting with a blankspace..
SQL
UPDATE table
SET column substring(column, 1)
WHERE column has blankspace
How can i do this?
EDIT
Oh yeah.
Reason is to erase blankspace...
Use LTRIM() function to remove starting blank spaces.
Try this:
UPDATE table SET column = LTRIM(column)
I think you should be explicit and use like:
UPDATE table
SET column = substring(column, 1)
WHERE column like ' %';

Find and remove quotes within table

So this is probably a stupid question and I've tried finding it within other find/replace posts but they didn't work/fit my problem.
I have a field in my table that randomly has a " at the beggining of the line and I wanted to know how I could find and remove these quotes.
Thanks!
I'm just guessing, but can you update your table, and set the column value to its same value without the strings?
String Replace
UPDATE TABLE
SET COLUMN = REPLACE(COLUMN_NAME, '"', '');
How about
UPDATE tbl SET fld = SUBSTR(fld, 2) WHERE fld LIKE '"%';
If you just want to remove the quote if it's the first character of the string then you can do something like this:
update your_table
set your_column = substr(your_column,2)
where left(your_column,1) = '"'

mysql - query to remove multiple characters from column content

Can I create a query using "replace" to remove more than one character\string from a column content ?
For example I have:
UPDATE table1 SET column1 = REPLACE(column1, '\r\n', '');
But what if I want to remove multiple characters or strings like:
<br />
<&nbsp>
<\r>
Is it possible to run this in single query ?
cascade it
UPDATE table1
SET column1 = replace(replace(REPLACE(column1, '\r\n', ''), '<br />',''), '<\r>','')