【问题标题】:Replace parenthesis and brackets in string替换字符串中的括号和方括号
【发布时间】:2016-12-19 14:49:09
【问题描述】:

我正在寻找一个正则表达式来替换所有括号和括号以及字符串中一对之间的内容。

我将regexp_replace(str_col, '\[(.*?)\]') 与 Amazon redshift 一起使用,但这只会替换括号,而不是其中的内容。

【问题讨论】:

  • 试试regexp_replace(str_col, '\\[[^]]*]')。您能否提供一个带有预期输出的示例文本?

标签: regex amazon-redshift


【解决方案1】:

由于 Amazon Redshift supports only POSIX regex,需要使用

1) 删除所有[...] 字符串:

regexp_replace(str_col, '\\[[^]]*]')

2) 删除所有(...) 字符串:

regexp_replace(str_col, '\\([^)]*\\)')

3) 删除两者:

regexp_replace(str_col, '\\[[^]]*]|\\([^)]*\\)')

【讨论】:

    最近更新 更多