Using Regex in ETL to check if a string ONLY contains digits?

I found that using the expression REGEXP_LIKE(field,'^[0-9]') will check if a string contains any digits. What I'm struggling to figure out is how to flag whether it ONLY contains digits and no other characters.

Best Answer

  • GrantSmith
    GrantSmith Coach
    edited July 29 Answer ✓

    Your regex is is actually only checking if the first digit contains a number

    ^ - Start of string

    [0-9] - Any single digit between 0 and 9

    You'll want to match the entire string:

    ^[0-9]+$
    

    + - Match one or more of the prior expression (in this case digits between 0 and 9)

    $ - match the end of the string

    **Was this post helpful? Click Agree or Like below**
    **Did this solve your problem? Accept it as a solution!**

Answers

  • GrantSmith
    GrantSmith Coach
    edited July 29 Answer ✓

    Your regex is is actually only checking if the first digit contains a number

    ^ - Start of string

    [0-9] - Any single digit between 0 and 9

    You'll want to match the entire string:

    ^[0-9]+$
    

    + - Match one or more of the prior expression (in this case digits between 0 and 9)

    $ - match the end of the string

    **Was this post helpful? Click Agree or Like below**
    **Did this solve your problem? Accept it as a solution!**