The free PRegEx xtra <http://www.openxtras.org/pregex/> has a sort method allowing you to create your own sorting function as a callback. I had a try with the list you provided as an example, and the following works, but

The reason I'm after an algorithm is that the integers may exist anywhere within the string.

herein lies the issue - knowing your data is at least half the battle. Anyway, here's an attempt that might get you started:
--
on mSort aList
-- example: aList = ["a 1", "d ", "a 10", "c 35", "a 100", "a 11", "a 12", "a 2", "a 21"]
  l = PRegEx_Sort(aList, 0, #mSortFunction)
  return l
end

on mSortFunction a, b
  --  put a, b

  tFound = re_m([a], "([0-9]+)", "g")
  if tFound then aNum = value(PRegEx_GetMatchString(1))
  tFound = re_m([b], "([0-9]+)", "g")
  if tFound then bNum = value(PRegEx_GetMatchString(1))

  tFound = re_m([a], "([A-Za-z]+)", "g")
  if tFound then aString = PRegEx_GetMatchString(1)
  tFound = re_m([b], "([A-Za-z]+)", "g")
  if tFound then bString = PRegEx_GetMatchString(1)

  --  put aNum, bNum
  --  put aString, bString
  --  put

  if aString < bString then return -1

  if aString = bString then
    if aNum < bNum then return -1
    if aNum = bNum then return  0
    if aNum > bNum then return  1
  end if

  if aString > bString then return  1
end

Cheers,
-Sean.

[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[email protected]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to