How do I access matched objects for replacement when using regular expression mode in PL/SQL Developer Find & Replace?

StackOverflow https://stackoverflow.com/questions/1614478

  •  06-07-2019
  •  | 
  •  

Question

I have a query where I want to replace

avg(j2)

with

avg(case when j2 <> 0 then j2 else 0 end)

The above is a specific example but the pattern is the same with all the replacements. It's always a word followed by a number that needs to be replaced with the case statement that checks if the number is not 0.

I tried the following for find:

avg(\(\w\d\))

and the find works. Now, I want to do a replace so I try:

avg(case when \1 <> 0 then \1 else 0 end)

but it puts literal \1 and not the captured text from the match. I tried \\1 & $1 as well and it takes all of them literally. Can anyone tell me what the right syntax is for using the captured text for replacement? Is this supported?

Thanks,

Ashish

Was it helpful?

Solution

I am not sure if the PL/SQL Developer IDE supports group capture. The recent versions do seem to support regex based find and replace though. Cant find a source to confirm if group capture works. Why dont you try pasting the code in a something like Notepad++ and try the same regex. It should work. You could paste the result back to your IDE and continue from there...

OTHER TIPS

You can replace it using $ and number like, $0 or $1 etc. see an example below

find: TABLE (.*\..*) IS
replace: COLUMN $1 IS

http://regexr.com/3gm6c

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top