Neil P
Neil P

Reputation: 3190

Does snowflake support positive lookbehind in a regex?

I want to use a positive lookbehind as part of my regexp_substr expression.

I have the below:

regexp_substr(My_Data, '(?<=id:).*(?=;)', 1, 1)

which gives me the below error:

Invalid regular expression: '(?<=id:).*(?=;)', no argument for repetition operator: ?

I'm trying to split key value pairs where I have

id:1234;

Upvotes: 2

Views: 4512

Answers (1)

Marcin Zukowski
Marcin Zukowski

Reputation: 4719

Look-behind is not supported in Snowflake's regexp.

However, you can use regular regexp groups for what you're trying to achieve:

select regexp_substr('Something,id=12345;Somethng', 'id=([^;]+);',1, 1, 'e');
-----------------------------------------------------------------------+
 REGEXP_SUBSTR('SOMETHING,ID=12345;SOMETHNG', 'ID=([^;]+);',1, 1, 'E') |
-----------------------------------------------------------------------+
 12345                                                                 |
-----------------------------------------------------------------------+

Note the 'e' argument for extraction, see the documentation.

Upvotes: 5

Related Questions