Groovy Function Strips Non-Numeric Characters From a String

Posted 11/27/2016 1:38 PM by Corey Klass

Here's a simple regular expression function that will strip non-numeric characters from a string. Useful for cleaning phone numbers.

// strips non-numeric values from a string
def stripNonNumeric(String stringIn) {
    def returnString = stringIn.replaceAll(/[^0-9]/, "")
    return returnString
}