Reputation: 1065
I want to replace the string in mysql using regular expression. For this, I am using REGEXP_REPLACE but it is not giving me the desired result.
I am trying to replace &breakUp=Mumbai;city,Puma;brand&
to &breakUp=Mumbai;city,Puma;brand,Delhi;State&
but regexp replace not giving me the desired result.
I am using the following sql query:
SELECT REGEXP_REPLACE('&breakUp=Mumbai;city,Puma;brand&','&breakUp=([\w;,]*)&','&breakUp=$1,Delhi;State&');
But it is giving me the following result:
&breakUp=Mumbai;city,Puma;brand&
The same regular expressions are working fine in other places except sql. How to resolve this in mysql and mariadb?
Upvotes: 0
Views: 744
Reputation: 43574
The \w
is not valid. You can use [[:alnum:]]
or [[:alpha:]]
instead of \w
:
Solution on MySQL:
SELECT REGEXP_REPLACE('&breakUp=Mumbai;city,Puma;brand&','&breakUp=([[[:alnum:]];,]*)&','&breakUp=$1,Delhi;State&');
Solution on MariaDB:
SELECT REGEXP_REPLACE('&breakUp=Mumbai;city,Puma;brand&','&breakUp=([[:alnum:];,]*)&','&breakUp=\\1,Delhi;State&');
Upvotes: 2