Oracle regexp_replace with group
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%
+1
source to share