Hey smorgasboard, I know that you already got an answer from TLM and that's cool, but I wanted to give your problem a try anyway as it interested me and this is what I came up with:
x := "
(
MARKS OF CANDIDATES
IN ROLL NUMBER ORDER
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
Record# ROLL NAME TOTAL CAT1 CAT2 CAT3 GENDER DEPTL
108901 9212000290 JEENSHA SATHAR 28.25 6 0 0 2 2
108902 9212000292 DINDU KG 38.50 6 0 0 2 2
result is
MARKS OF CANDIDATES
IN ROLL NUMBER ORDER
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
Record# ROLL NAME TOTAL CAT1 CAT2 CAT3 GENDER DEPTL
1. 108902 9212000292 DINDU KG 38.50 6 0 0 2 2
2. 108901 9212000290 JEENSHA SATHAR 28.25 6 0 0 2 2
)"
x := RegExReplace(x, "m`a)(?:(.*?(\d{1,3}\.\d\d ).*$\R?)|.*$\R?)", "$2$1")
Sort x, N
x := RegExReplace(x, "m`a)\d{1,3}\.\d\d (.*$\R?)", "$1")
MsgBox %x%
Here is a more detailed and commented version:
;// I'm slowly migrating to this as my newline match.
NL := "\R"
;// This sub regex is the number that must exist in the line to match
NUMBER := "\d{1,3}\.\d\d "
;// This regex describes a line that I want and puts it in the 1st capture group.
;// Further, put the number of interest in the 2nd capture group.
WANT := "(.*?(" NUMBER ").*$" NL "?)"
;// This regex states match that line that I want *or* still match the line
;// but don't put it in a capture group.
DO_OR_DONT_WANT := "(?:" WANT "|.*$" NL "?)"
;// If what I want is found, capture groups 1 and 2 are populated otherwise
;// they are empty. Put 2nd capture group infront of 1st.
x := RegExReplace(x, "m`a)" DO_OR_DONT_WANT, "$2$1")
;// sort the lines
Sort x, N
;// Remove the leading number used to sort on
x := RegExReplace(x, "m`a)" NUMBER "(.*$" NL "?)", "$1")
;// you know ;)
MsgBox %x%
I found the problem interesting and learned a few things from it. Here's hoping that it does the same for you.
I would also be interested in seeing what TLM's solution was. He comes up with some great stuff!
Thanks, and happy holidays!
Adrian