Reputation: 1061
To remove all non-alpha numeric chars, the regex would be
x = regexp_replace(somestring, '[^a-zA-Z0-9]+', '', 'g')
But what if I want to leave underscores untouched ?
Upvotes: 18
Views: 18425
Reputation: 7739
Then you need to use :
x = regexp_replace(somestring, '\W+', '', 'g')
\W
is the same as [^a-zA-Z0-9_]
Upvotes: 27
Reputation: 14453
How about using '\W+' that replaces all non a-z and 0-9 leaving _ alone
So
x = regexp_replace(somestring, '\W+', '', 'g')
Upvotes: 2