I’m having trouble figuring out how to write a regex in Snowflake that will return the last 7-digit number from a string. Non-working example:
SELECT REGEXP_SUBSTR(‘4000400 – Widget Revenue:4000401 – Special
Widgets:4000422 – Tiny Special Widgets’, ‘\D*\d+\D+(\d+).*’)
>Solution :
Using '(\\d{7})(\\D*)$' and accessing first subgroup:
SELECT REGEXP_SUBSTR('4000400 - Widget Revenue:4000401 - Special Widgets:4000422 - Tiny Special Widgets'
,'(\\d{7})(\\D*)$',1,1,'e',1) AS result
Output:
4000422