Friday, October 15, 2010

Oracle 10g Regular Expression Replace Function

Replace Repeating Characters with Single Character

Ex: RAAGHHUUUUUUUUUUUUUUU  with RAGHU

SELECT regexp_replace ('RAAGHHUUUUUUUUUUUUUUU', '([A-Z])\1{1,}', '\1') from dual

Output::- RAGHU

The \1 refers to the previous character and check {1,} 1 or more times and replace with the same character. This is called Backward reference.

Remove any Special Charaters other than Alphabets and Number

Ex:- RAJ33*#$%+_HU

select regexp_replace (p_str, '([^A-Z0-9])', '') from dual

Ouput - RAJ33HU

Removes all other characters expect number and Alphabets

No comments:

Post a Comment