Skip to content
Advertisement

SQL – Extracting first 5 consecutive numbers from alphanumeric string

I am using AWS Athena, so functions are a bit limiting. But essentially I want to extract the first 5 consecutive and sequential numbers from a alphanumeric field.

enter image description here

From the first example, you can see it ignores the first 1 because there aren’t 4 trailing numbers. I want to find and extract the first 5 numbers that are given together from this field. The output field is what I am hoping to achieve.

Advertisement

Answer

This will find an exact sequence of 5 digits.
a sequence of less or more than 5 digits will be ignored.



User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement