Simple Find and Replace

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
rrhandle
Posts: 11
Joined: Thu Mar 23, 2006 4:03 pm

Simple Find and Replace

Post by rrhandle »

I HAVE THIS
------------------------
Dim x: asdfasdfasdf
Dim y: rwefnmwlkej

I WANT THIS
------------------------
[Dim x:] asdfasdfasdf
[Dim y:] rwefnmwlkej

THIS IS WANT I USED
------------------------
Find What: D[^()]*:
Replace: [\1]

THIS IS WHAT I GET
------------------------
[\1]asdfasdfasdf
[\1]rwefnmwlkej

What am I doing wrong?
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

The \1 in your replacement expression doesn't refer tio anything, as there are no capturing parentheses in your regular expression.

Either use \0, which refers to the entire text that was matched:
Find what: D[^()]*:
Replace with: [\0]

[X] Regular expression
or insert some capturing parentheses:
Find what: (D[^()]*:)
Replace with: [\1]

[X] Regular expression
This assumes you are using Posix regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
rrhandle
Posts: 11
Joined: Thu Mar 23, 2006 4:03 pm

Post by rrhandle »

Thank you! One change I had to make was to remove the square brackets. i.e. \1 workes but [\1] does not. Can you explain that?
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

No I can't. It does what you asked for. In what way does it not work?
Post Reply