How does one sort an array based on a substring of each element ?
e.g. given an array like
arr=( 2some05stuff 4more02stuff 3evenmore01stuff 1no04stuff )
I'd like to sort the elements by the numerical string that precedes stuff
so I end up with
3evenmore01stuff
4more02stuff
1no04stuff
2some05stuff
I know that parameter expansion flags o
/O
reorder an array e.g.
print -rl "${(@on)arr}"
1no04stuff
2some05stuff
3evenmore01stuff
4more02stuff
and
print -rl "${(@On)arr}"
4more02stuff
3evenmore01stuff
2some05stuff
1no04stuff
I just don't know if it's possible to combine them flags with a function or other parameter expansion like e.g. subscript removal or subscript expansion...