Toad World® Forums

Replace with template

So I got curious about something that was said a couple of months ago.

There was a discussion about using macros to wrap strings in quotes and replacing carriage return/line feeds with commas. I have always used macros as described in the online help, one for each task, but someone, I don’t recall who, maybe Mark… said it could be done in one step.

Then I got curious about “replace with template” and it seems like the way to go, but I can’t seem to get it to work.

I have the following working:

Find: ^.*?$ Replace with: ‘$0’ regular expressions option on

Find: \r\n Replace with: , regular expressions option on

Those work perfectly just as they always have. So after looking at the online help on replace with template I tried using templates as

Find: (^.*?$)(\r\n) Replace with: \1’$0’\2, regular expressions and replace with template on

But it’s not working.

xxx

yyy

zzz

becomes

xxx’xxx

,yyy

Zzz

Any idea what I’m doing wrong? This is in 12.8.0.13

Chris Johnson

IT Systems Analyst

Distribution Logistics

615-855-4371

You want to use Search/Replace Macros. From the replace dialog click the right-most button. You can also get to it from the little dropdown beside the replace button on the toolbar. Once in there, paste all of the code at the bottom into the left side. Click OK, etc. to get out of there. Now, click the dropdown beside the replace button and choose “Demo” with your text in the Editor. It should do what you want.

Ignore the help. For some reason whenever regex is involved the Toad help has always tried to explain it in too much detail and getting it wrong in the process. There are numerous online resources for regex. Replace with Template will convert \t to Tab, \r to Carriage Return, \n to Line Feed in the replacement text and that’s all. The \1, \2, $1, $2, etc. syntax is standard regex syntax to swap in those sub-expressions into the replacement text. www.regular-expressions.info is a decent resource, it was better before the re-design, but I believe that all of the info is still there somewhere. Toad follows the Perl syntax.

object TComponentCollection
Items = {
545046300F5474645265706C6163654D6163726F000A436F6C6C656374696F6E
07085F312E4F776E65720B446973706C61794E616D65060444656D6F0D49676E
6F72654661696C757265080A4D6163726F47726F7570090C5365617263684F72
6967696E070D736F456E7469726553636F70650C577261705365617263686573
080F50726F6D70744F6E5265706C616365080A5465787446696E6465720A7500
0000545046300F547464546578745265706C61636572000D4361736553656E73
69746976650811526567756C617245787072657373696F6E080F536561726368
446972656374696F6E07097364466F72776172640A57686F6C65576F72647308
135265706C6163655769746854656D706C617465080000054974656D730A1103
0000545046301F547464437573746F6D5365617263685265706C6163654D6163
726F4C69737400054974656D730ADF020000545046300F5474645265706C6163
654D6163726F000B446973706C61794E616D65060E5772617020696E2051756F
7465730D49676E6F72654661696C757265080A4D6163726F47726F7570080C53
65617263684F726967696E070D736F456E7469726553636F70650C5772617053
65617263686573080F50726F6D70744F6E5265706C616365080A546578744669
6E6465720A9C000000545046300F547464546578745265706C61636572000D43
61736553656E7369746976650811526567756C617245787072657373696F6E09
0A5365617263685465726D0608283F6D295E2E2A240F53656172636844697265
6374696F6E07097364466F72776172640A57686F6C65576F726473080B526570
6C61636554657874060427243027135265706C6163655769746854656D706C61
7465080000054974656D730A32000000545046301F547464437573746F6D5365
617263685265706C6163654D6163726F4C69737400054974656D730A00000000
00000000545046300F5474645265706C6163654D6163726F000B446973706C61
794E616D65060F436F6D6D612044656C696D697465720D49676E6F7265466169
6C757265090A4D6163726F47726F7570080C5365617263684F726967696E070D
736F456E7469726553636F70650C577261705365617263686573080F50726F6D
70744F6E5265706C616365080A5465787446696E6465720A9600000054504630
0F547464546578745265706C61636572000D4361736553656E73697469766508
11526567756C617245787072657373696F6E090A5365617263685465726D0604
5C725C6E0F536561726368446972656374696F6E07097364466F72776172640A
57686F6C65576F726473080B5265706C6163655465787406022C20135265706C
6163655769746854656D706C617465080000054974656D730A32000000545046
301F547464437573746F6D5365617263685265706C6163654D6163726F4C6973
7400054974656D730A000000000000000000000000}
end

I’m supposed to copy everything from “object” down through “end”

Yes.

I don’t understand the “into the left side” part.

The search/replace macro editor GUI is divided into two parts. The left side showing macros and the right side showing the definition of the selected macro. Click in the left side and paste.

I need to go through there and clean things up to surface it better and make it more intuitive. “Groups” is a terrible name for the top-most level. It should just be “Macro” like everything else (or script as you call it) and a macro/script can have sub-macros. The feature is incredibly powerful, but hidden sufficiently to make it less used I’d guess. The “Ignore failure” checkbox should be intuitive, but if unchecked and that macro fails to match then the entire sequence stops dead in its tracks. If checked the next action is executed.

Sorry Michael, I don’t seem to understand these instructions, other than “ignore the help, it’s wrong”.

I know how to get to the macro editor, unless we aren’t talking about the same editor. I don’t see how to paste that code. I “assume” I’m supposed to copy everything from “object” down through “end”, but I don’t understand the “into the left side” part.

From: Michael Staszewski [mailto:bounce-mstaszew@toadworld.com]

Sent: Tuesday, July 28, 2015 9:31 AM

To: toadoraclebeta@toadworld.com

Subject: RE: [Toad for Oracle - Beta Discussion Forum] Replace with template

RE: Replace with template

Reply by Michael Staszewski

You want to use Search/Replace Macros. From the replace dialog click the right-most button. You can also get to it from the little dropdown beside the replace button on the toolbar. Once in there, paste all of the code at the bottom into the left side. Click OK, etc. to get out of there. Now, click the dropdown beside the replace button and choose “Demo” with your text in the Editor. It should do what you want.

Ignore the help. For some reason whenever regex is involved the Toad help has always tried to explain it in too much detail and getting it wrong in the process. There are numerous online resources for regex. Replace with Template will convert \t to Tab, \r to Carriage Return, \n to Line Feed in the replacement text and that’s all. The \1, \2, $1, $2, etc. syntax is standard regex syntax to swap in those sub-expressions into the replacement text.
www.regular-expressions.info
is a decent resource, it was better before the re-design, but I believe that all of the info is still there somewhere. Toad follows the Perl syntax.

object TComponentCollection

Items = {

545046300F5474645265706C6163654D6163726F000A436F6C6C656374696F6E

07085F312E4F776E65720B446973706C61794E616D65060444656D6F0D49676E

6F72654661696C757265080A4D6163726F47726F7570090C5365617263684F72

6967696E070D736F456E7469726553636F70650C577261705365617263686573

080F50726F6D70744F6E5265706C616365080A5465787446696E6465720A7500

0000545046300F547464546578745265706C61636572000D4361736553656E73

69746976650811526567756C617245787072657373696F6E080F536561726368

446972656374696F6E07097364466F72776172640A57686F6C65576F72647308

135265706C6163655769746854656D706C617465080000054974656D730A1103

0000545046301F547464437573746F6D5365617263685265706C6163654D6163

726F4C69737400054974656D730ADF020000545046300F5474645265706C6163

654D6163726F000B446973706C61794E616D65060E5772617020696E2051756F

7465730D49676E6F72654661696C757265080A4D6163726F47726F7570080C53

65617263684F726967696E070D736F456E7469726553636F70650C5772617053

65617263686573080F50726F6D70744F6E5265706C616365080A546578744669

6E6465720A9C000000545046300F547464546578745265706C61636572000D43

61736553656E7369746976650811526567756C617245787072657373696F6E09

0A5365617263685465726D0608283F6D295E2E2A240F53656172636844697265

6374696F6E07097364466F72776172640A57686F6C65576F726473080B526570

6C61636554657874060427243027135265706C6163655769746854656D706C61

7465080000054974656D730A32000000545046301F547464437573746F6D5365

617263685265706C6163654D6163726F4C69737400054974656D730A00000000

00000000545046300F5474645265706C6163654D6163726F000B446973706C61

794E616D65060F436F6D6D612044656C696D697465720D49676E6F7265466169

6C757265090A4D6163726F47726F7570080C5365617263684F726967696E070D

736F456E7469726553636F70650C577261705365617263686573080F50726F6D

70744F6E5265706C616365080A5465787446696E6465720A9600000054504630

0F547464546578745265706C61636572000D4361736553656E73697469766508

11526567756C617245787072657373696F6E090A5365617263685465726D0604

5C725C6E0F536561726368446972656374696F6E07097364466F72776172640A

57686F6C65576F726473080B5265706C6163655465787406022C20135265706C

6163655769746854656D706C617465080000054974656D730A32000000545046

301F547464437573746F6D5365617263685265706C6163654D6163726F4C6973

7400054974656D730A000000000000000000000000}

end

To reply, please reply-all to this email.

Stop receiving emails on this subject.

Or
Unsubscribe from Toad for Oracle - Beta
notifications altogether.

Toad for Oracle - Beta Discussion Forum

Flag
this post as spam/abuse.

Oh, I see… just paste it into the left side without creating anything first. That didn’t seem particularly intuitive, but now that I’ve done it I see what you mean.

Yes, that does what I want, thanks.

So it looks like you created a group and added the two component replaces under it making it essentially a script. I wondered what groups were for other than just as on organizational structure.

Very cool. Thanks!

From: Michael Staszewski [mailto:bounce-mstaszew@toadworld.com]

Sent: Thursday, July 30, 2015 8:35 AM

To: toadoraclebeta@toadworld.com

Subject: RE: [Toad for Oracle - Beta Discussion Forum] RE: [Toad for Oracle - Beta Discussion Forum] Replace with template

RE: RE: [Toad for Oracle - Beta Discussion Forum] Replace with template

Reply by Michael Staszewski

I’m supposed to copy everything from “object” down through “end”

Yes.

I don’t understand the “into the left side” part.

The search/replace macro editor GUI is divided into two parts. The left side showing macros and the right side showing the definition of the selected macro. Click in the left side and paste.

To reply, please reply-all to this email.

Stop receiving emails on this subject.

Or
Unsubscribe from Toad for Oracle - Beta
notifications altogether.

Toad for Oracle - Beta Discussion Forum

Flag
this post as spam/abuse.