Regular Expression Special Character Elimination
I have a string like '11dd$%e11!@h' Can I have a regular expression to remove only special character from the above string. Character and number should be there after special chara
Solution 1:
select'11dd$%e11!@h'as input, regexp_replace('11dd$%e11!@h', '[^[:alnum:]]') as output
from dual
;
INPUT OUTPUT
------------ --------
11dd$%e11!@h 11dde11h
[:alnum:] is shorthand for all letters (standard ASCII letters, lower and upper case) and all digits. [^ ... ] means everything EXCEPT .... So, this will replace everything EXCEPT letters and digits with... nothing (since we didn't give a third argument to REGEXP_REPLACE).
EDIT: The OP added a second part to the question.
If the assignment is to remove all the alpha-numeric characters ONLY, and to keep everything else, simply remove the ^ from the regular expression.
select'11dd$%e11!@h'as input, regexp_replace('11dd$%e11!@h', '[[:alnum:]]') as output
from dual
;
INPUT OUTPUT
------------ ------
11dd$%e11!@h $%!@
Post a Comment for "Regular Expression Special Character Elimination"