Page 1 of 1

Delete before & after

Posted: Mon Jun 02, 2008 2:48 pm
by insolitude
Hi, I have file with a few thousands lines of text. Each line contains a match to the following regular expression:

("................")

I want to delete all characters before & after the regular expression, leaving me with only the characters matching the regular express (one match per line). Is this possible? The number of characters before & after vary from line to line.

Thanks!

*** UPDATE ***

I figured out how to find what I need

.*("................")

OR

("................").*

Now I just need to figure out how to do a replace that preserves the ("................"). Obviously this doesn't work:

FIND: .*("................")
REPLACE: ("................")

How do I replace to preserve the original characters matching ("................")?

Posted: Mon Jun 02, 2008 4:11 pm
by Bob Hansen
From HELP on Regular Expressions:
Using the \1 or \2 or \3 as an example will replace the first, second, and third groups of (characters) in parenthesis.

Expression Definition
& Substitute the text matching the entire search pattern.
\0 to \9 Substitute the text matching tagged expression 0 through 9. \0 is equivalent to &.

---------------------------------------

Using the \1 or \2 or \3 as an example will replace the first, second, and third groups of (characters) in parenthesis.

Search for: *.(xxxxxxx)
Replace with: \1
Will result with xxxxxxx

Search for (aaaaa).*(bbbbb)
Replace with: \2-\1
Will result with bbbbb-aaaaa

Search for: (abc).*(def)([0-9]{3})
Replace with: \2\3
Will result in def followed by 3 digits.