Hi All,
I am trying to understand the behaviour of
REGEXP_REPLACE when there is a backslash in the subject string. It appears that the subject needs to have \'s escaped which is not desirable (see example 1 below). I can understand having to escape \'s in the regex, but not the subject string.
Any suggestions?
Thanks.
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 397751
Server version: 10.11.5-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> SELECT REGEXP_REPLACE('Et12\4', '^Et', 'Ethernet');
+---------------------------------------------+
| REGEXP_REPLACE('Et12\4', '^Et', 'Ethernet') |
+---------------------------------------------+
| Ethernet124 |
+---------------------------------------------+
1 row in set (0.000 sec)
MariaDB [(none)]> SELECT REGEXP_REPLACE('Et12\\4', '^Et', 'Ethernet');
+----------------------------------------------+
| REGEXP_REPLACE('Et12\\4', '^Et', 'Ethernet') |
+----------------------------------------------+
| Ethernet12\4 |
+----------------------------------------------+
1 row in set (0.000 sec)
MariaDB [(none)]> SELECT REGEXP_REPLACE('Et12/4', '^Et', 'Ethernet');
+---------------------------------------------+
| REGEXP_REPLACE('Et12/4', '^Et', 'Ethernet') |
+---------------------------------------------+
| Ethernet12/4 |
+---------------------------------------------+
1 row in set (0.000 sec)
MariaDB [(none)]> SELECT REGEXP_REPLACE('Et12 4', '^Et', 'Ethernet');
+---------------------------------------------+
| REGEXP_REPLACE('Et12 4', '^Et', 'Ethernet') |
+---------------------------------------------+
| Ethernet12 4 |
+---------------------------------------------+
1 row in set (0.000 sec)