1

I try this

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

It supose to transform 'hello world word' in '$hello% $world% $word%'

The Oracle documentation is not clear about the founction regexp_replace with group...

0

1 Answer 1

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

\1 gives you the string matching the pattern and then we format it appending the other characters required.

[a-zA-Z]+ looks for all continuous sequence of Alphabets.

([[:alnum:]]+) will look for sequence of alphanumeric characters. If you want one, 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

Sign up to request clarification or add additional context in comments.

1 Comment

I agree with your approach, but you should change '%\1$' to '$\1%' to correspond with the requirement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.