Oracle Database Regular expression


Example

Let's say we want to replace only numbers with 2 digits: regular expression will find them with (\d\d)

SELECT REGEXP_REPLACE ('2, 5, and 10 are numbers in this example', '(\d\d)', '#')
FROM dual;

Results in:

'2, 5, and # are numbers in this example'

If I want to swap parts of the text, I use \1, \2, \3 to call for the matched strings:

 SELECT REGEXP_REPLACE ('swap around 10 in that one ', '(.*)(\d\d )(.*)', '\3\2\1\3')
 FROM dual;