Search code examples
snowflake-cloud-data-platform

Snowflake REGEX to identify if column contains any digit


I currently have select REGEXP_LIKE(col, '[0-9]+') which seems to return True only if all the characters in the string are numeric.

For example, it returns True for 12345 but False for something like 100 Apple St.

What is the necessary regex pattern to return True in both examples above?


Solution

  • To check if a column contains any digit, you can modify your current pattern to use the .* character to match any number of characters before or after the digit(s):

    SELECT REGEXP_LIKE(col, '.*[0-9].*')