Page 1 of 1

find, copy, replace then insert -- help needed

Posted: Sat Jan 12, 2008 4:31 am
by jahmus
I would like to find a line that begins with a variable number of spaces and\or tabs, contains a known string and ends with a variable number of spaces and\or tabs and then a slash

Line to find:

xxx9.lib \

Then replace part of the string (9) with (9_1) and insert it after the orignal string with the same leading spaces and\or tabs.

Result:

xxx9.lib \
xxx9_1.lib \

Any help would be apperciated, particularlly around the replacement part.

Posted: Sat Jan 12, 2008 7:53 am
by MudGuard
I'll use _ to mark a space in the search expression. The _ in the replacement is a real _ ;-)

Line beginning: ^
variable number of spaces or tabs, even zero: [_\t]*
Backslash (needs to be escaped, otherwise it would escape the following character!): \\
Line end: $
you want to keep some parts so remember them by putting () around them
in the replace value use \1, \2, \3 ... for the remembered parts

This will result in

Search for:

Code: Select all

^([_\t]*xxx9)(.lib[_\t]*\\)$
Replace by

Code: Select all

\1_1\2

Posted: Sat Jan 12, 2008 10:34 am
by ben_josephs
That's the TextPad way; it won't work in WildEdit, which uses Perlish regular expressions, which are far more powerful.

You need something like
Find what: ^(\s*)9\.lib(\s*\\)
Replace with: $1(9_1.lib)$2

[X] Regular expression
[X] Replacement format