Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Snowflake REGEX to get last 7-digit number in a string

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+).*’)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading