Removing certain characters in all rows that match a regex?
Posted
by
user001
on Stack Overflow
See other posts from Stack Overflow
or by user001
Published on 2012-06-30T14:13:42Z
Indexed on
2012/06/30
15:16 UTC
Read the original article
Hit count: 166
I'd like to change
{foo, {bar}, foobar}
to
{foo, bar, foobar}
in all rows that match '{.*{'
. I.e. remove all curly braces { and } except the outer most pair.
So doing
mysql -h $H -u $U -p$P $DB -B -e "SELECT id FROM t WHERE col REGEXP '{.*{'" > bad.txt
selects all the rows that will need this substitution. How do I make this substitution very quickly?
EDIT:
Could I do it by
update table set column = REPLACE(column,'{','');
Then restore the out most pair
update table set column = REPLACE(column,'^','{');
update table set column = REPLACE(column,'$','}');
© Stack Overflow or respective owner