Oracle regexp_replace with group

I try this

SELECT regexp_replace(v_gen,'(\b[a-zA-Z]+\b)','$$1%')INTO v_test FROM DUAL;

It must convert 'hello world word'

to '$hello% $world% $word%'

There is no clear understanding of use regexp_replace

with group in Oracle documentation ...

0


source to share


1 answer


regexp_replace('hello world word','([a-zA-Z]+)','$\1%')

      

\1

gives you a string that matches the pattern, and then we'll format it by adding other characters as required.

[a-zA-Z]+

searches for the entire continuous sequence of alphabets.

([[:alnum:]]+)

will search for a sequence of alphanumeric characters. If you want you can use this.



Example: with multiple options

with my_text as
(
  select 'hello world word' as str from dual
)
SELECT regexp_replace(str,'([[:alnum:]]+)','$\1%') FROM my_text
union all
SELECT regexp_replace(str,'([[:alpha:]]+)','$\1%') FROM my_text
union all
SELECT regexp_replace(str,'([a-zA-Z]+)','$\1%') FROM my_text

REGEXP_REPLACE(STR,'([
----------------------
$hello% $world% $word%
$hello% $world% $word%
$hello% $world% $word%

      

SQLFiddle Demo

+1


source







All Articles