Hound
Hound

Reputation: 972

Redshift regexp_substr

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>>>&|$'.

Upvotes: 2

Views: 4690

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626738

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 &

Upvotes: 5

Related Questions