Page 1 of 1

Is this 'group sorting' amenable to Regex?

Posted: Wed May 25, 2016 2:03 pm
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

Posted: Thu May 26, 2016 8:48 am
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.

Posted: Sat May 28, 2016 11:26 am
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

Posted: Sat May 28, 2016 1:58 pm
by ben_josephs
You edit text using Excel?!

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