Redshift regexp_substr

被刻印的时光 ゝ 提交于 2021-02-04 20:55:29

问题


I want to replicate this regex pattern to regexp_substr. I want to capture the second group.

'(\?)(.*?)(&|$)'

I have tried this

regexp(my_url, '\\?.*?&|$')

And some similar variations of the above, but I have been getting the errror: ERROR: XX000: Invalid preceding regular expression prior to repetition operator. The error occured while parsing the regular expression: '\?.*?>>>HERE>>>&|$'.


回答1:


Since Amazon Redshift supports only POSIX regex, you need to use greedy quantifiers rather than lazy ones, but with a negated character class:

regexp(my_url, '\\?([^&]*)')

The pattern matches:

  • \? - a question mark
  • ([^&]*) - Group 1: zero or more chars other than &


来源:https://stackoverflow.com/questions/46495580/redshift-regexp-substr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!