java remove all non numeric characters from string code example

Example 1: t-sql remove all non-alphanumeric characters from a string

Create Function [dbo].[RemoveNonAlphaCharacters](@Temp VarChar(1000))
Returns VarChar(1000)
AS
Begin

    Declare @KeepValues as varchar(50)
    Set @KeepValues = '%[^a-z]%'
    While PatIndex(@KeepValues, @Temp) > 0
        Set @Temp = Stuff(@Temp, PatIndex(@KeepValues, @Temp), 1, '')

    Return @Temp
End

Example 2: java remove non numbers from string

String str = "a12.334tyz.78x";
str = str.replaceAll("[^\\d.]", "");

Example 3: remove special characters from string python

>>> string = "Special $#! characters   spaces 888323"
>>> ''.join(e for e in string if e.isalnum())
'Specialcharactersspaces888323'

Tags:

Java Example