Weird behaviour with escape of REGEX in MySQL -
can please explain me behaviour?
mysql> select *, ('http://www.thisisatest.es/?utm_source=xxxx&utm_term=&utm_campaign=xxxx&utm_medium=xxxx' regexp rule) r containers_rules; +---------------------------------------------------------------------------------------+------+ | rule | r | +---------------------------------------------------------------------------------------+------+ | ^http://www.thisisatest.es/\\?utm_source | 0 | | ^http://www.thisisatest.es/\?utm_source | 1 | +---------------------------------------------------------------------------------------+------+ 5 rows in set (0.01 sec) mysql> select 'http://www.thisisatest.es/?utm_source=xxxx&utm_term=&utm_campaign=xxxx&utm_medium=xxxx' regexp '^http://www.thisisatest.es/\\?utm_source' r; +---+ | r | +---+ | 1 | +---+ 1 row in set (0.00 sec) i don't understand why manual regex comparing needs 2 "\" , dynamic regex comparing 1 "\" or won't work?
i bit lost...
the result set you're seeing shows column values (i.e. without additional escape characters).
however, string literal does require additional backslash; example, insert statement sec row have been:
insert ... values ('^http://www.thisisatest.es/\\?utm_source') and matches manual query.
mysql regex
No comments:
Post a Comment