Page 1 of 1

Simple Find and Replace

Posted: Thu Apr 10, 2008 1:19 am
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?

Posted: Fri Apr 11, 2008 7:48 am
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

Posted: Sat Apr 12, 2008 6:44 pm
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?

Posted: Sun Apr 13, 2008 9:47 am
by ben_josephs
No I can't. It does what you asked for. In what way does it not work?