Reducing a list

General questions about using TextPad

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

Post Reply
User avatar
tcebob
Posts: 80
Joined: Fri Mar 28, 2003 1:20 am

Reducing a list

Post by tcebob »

Here's an abbreviated list of parenthetical lists. I tried and failed to use an RE to delete averything except those lists beginning with (10, resulting in (10 a b)(10 c d)(10 e f) etc. Any suggestions?

tcebob

code
(38 . 0.0) (39 . 0.0) (10 16.497 3.71905) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 16.308 3.62263) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 16.2112 3.47429) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 16.2823 3.32199) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 16.6007 3.20692) (40 . 0.0) (41 . 0.0) (42 . 0.0)
(10 17.6133 3.13585)
code
would become
code
(10 16.497 3.71905)(10 16.308 3.62263)(10 16.2112 3.47429)
(10 16.2823 3.32199)(10 16.6007 3.20692)(10 17.6133 3.13585)
code
ben_josephs
Posts: 2459
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

If the lists you want to delete are all those that don't begin with (10 followed by a space, then you can delete every list whose contents do not have a 1 in the first position, or do not have a 0 in the second position, or do not have a space in the third position:
Find what: -*\(([^1]..|.[^0].|..[^-])[^)]*\)-* [Replace the hyphens with spaces]
Replace with: [nothing]

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

[X] Use POSIX regular expression syntax
This sort of thing is much easier in WildEdit (http://www.textpad.com/products/wildedit/), in which you can use a negative lookahead assertion to cause a regular expression not to match at a position at which some subexpression does match:
Find what: -*\((?!10-)[^)]*\)-*
Replace with: [nothing]

[X] Regular expression
Look up lookahead in WildEdit's help.
User avatar
tcebob
Posts: 80
Joined: Fri Mar 28, 2003 1:20 am

Post by tcebob »

Thanks, Ben-josephs. Here's a peek at the results:

" (10 16.497 3.71905) (10 16.308 3.62263) ( ". . .

Close enough. I did change the -s to sp. and can strip the left-over spaces easily. (actually, lisp doesn't care abouth the spaces.)

tcebob
User avatar
tcebob
Posts: 80
Joined: Fri Mar 28, 2003 1:20 am

Post by tcebob »

er. . .

When the list went in there were spaces between each )(. Should have said "code," I guess.

tcebob
Post Reply