为什么这个会起作用:
SELECT REGEXP_REPLACE(REGEXP_REPLACE('[GREY]', '\]', ''), '\[', '')
但这些不是:
SELECT REGEXP_REPLACE('[GREY]', '[\[\]]', '')
SELECT REGEXP_REPLACE('[GREY]', '/[\[\]]/g', '')
这是来自regex101.com的解释:
/[\[\]]/g
Match a single character present in the list below [\[\]]
\[ matches the character [ literally (case sensitive)
\] matches the character ] literally (case sensitive)
Global pattern flags
g modifier: global. All matches (don't return after first match)
匹配信息:
Match 1
Full match 0-1 `[`
Match 2
Full match 5-6 `]`
答案 0 :(得分:1)
REGEXP_REPLACE
带有标志,例如g
作为单独的参数:
SELECT REGEXP_REPLACE('[GREY]', '[\[\]]', '', 'g')
返回GREY