Is this 'group sorting' amenable to Regex?

General questions about using TextPad

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

Post Reply
terrypin
Posts: 174
Joined: Wed Jul 11, 2007 7:50 am

Is this 'group sorting' amenable to Regex?

Post by terrypin »

A couple of hours of unsuccesfull attempts and I'm ready to give in, but before I do so I'd appreciate any suggestions please.

I want content like this :

*** "Status - Category or Overlay"
Count entries in category (no display): 5

*** "Icons - Making new ones"

*** "Overlay name to variable + registry"
Track: Test for GPS data: 6
Find any GPX on C: with that overlay name: 3
Timestamps (add): 9
Track to GE + files (single, silent): 12
Open track in GPSU: 10

*** "Capture current mark position"



to become alphabetically organised by the 'headers', like this:

*** "Capture current mark position"

*** "Icons - Making new ones"

*** "Overlay name to variable + registry"
Track: Test for GPS data: 6
Find any GPX on C: with that overlay name: 3
Timestamps (add): 9
Track to GE + files (single, silent): 12
Open track in GPSU: 10

*** "Status - Category or Overlay"
Count entries in category (no display): 5


(Note that some headers have no following entries.)

Even better would be for the entries to be sorted alphabetically too, like this:

*** "Capture current mark position"

*** "Icons - Making new ones"

*** "Overlay name to variable + registry"
Find any GPX on C: with that overlay name: 3
Open track in GPSU: 10
Timestamps (add): 9
Track: Test for GPS data: 6
Track to GE + files (single, silent): 12

*** "Status - Category or Overlay"
Count entries in category (no display): 5


Beyond the scope of TextPad?

--
Terry, East Grinstead, UK
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

You can sort the groups in three steps.

1. Replace each newline that is not followed by *** by some string that doesn't occur elsewhere, say ~~~~ .
Find what: \n(?!^\*\*\*)
Replace with: ~~~~
2. Sort the lines.

3. Replace each ~~~~ with newline:
Find what: ~~~~
Replace with: \n
Sorting the records within the groups is a job for a script.
terrypin
Posts: 174
Joined: Wed Jul 11, 2007 7:50 am

Post by terrypin »

Thanks a lot, Ben.

I tried pasting into Excel 2000 and a friend wrote me a neat Excel VBA macro that works nicely. So I'll use that.

Great Regex learning exercise for me though, thank you.

--
Terry, East Grinstead, UK
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

You edit text using Excel?!

II wrote a program in VBA once. It made me ill.
Post Reply