Reputation: 69
I'm quite new to regular expressions and I'm not getting what I expect while using regex in MySql. I did investigate these regex expressions at "https://regexr.com/" which is giving me results that are what I expect. The query below returns 3 columns:
SELECT
# 0, 6
REGEXP_INSTR("Birch Street, Boston, MA 02131, United States", "\s+street") one_or_more,
# 7, 6
REGEXP_INSTR("Birch Street, Boston, MA 02131, United States", "\s*street") zero_or_more,
# 7, 6
REGEXP_INSTR("Birch Street, Boston, MA 02131, United States", "\s?street") zero_or_once
FROM
DUAL;
Any helps is appreciated. Thank you. Paul
Upvotes: 0
Views: 59
Reputation: 56162
You need to use double \
, in this case you'll get the expected results, i.e.:
REGEXP_INSTR("Birch Street, Boston, MA 02131, United States", "\\s+street")
To use a literal instance of a special character in a regular expression, precede it by two backslash (\) characters. The MySQL parser interprets one of the backslashes, and the regular expression library interprets the other.
https://dev.mysql.com/doc/refman/8.0/en/regexp.html#regexp-syntax
Upvotes: 1