Using my quick-intuition, are these methods sorting on the earliest number withing the string, ignoring the non-digits?
$ raku -e '.say for <bk10 bk34 bk2 bk1>.sort: {m/ \d+ /.Int}' $ raku -e '.say for <bk10 bk34 bk2 bk1>.sort: +*.match: / \d+ /' let's see $ raku -e '.say for <say31 what20 the30letters40 does2 not3 it1 matter10>.sort: {m/ \d+ /.Int}' it1 does2 not3 matter10 what20 the30letters40 say31 What's been interesting about this thread is not only the variety of solutions, also that the solutions are for two different questions- how to sort by alpha & numeric segments (b3b, a1a, c20c) => (a1a, b3b, c2c) how to sort by a numeric segment only (b3b, a1a, c20c) => (a1a, b3b, c20c) -y On Thu, Mar 7, 2024 at 4:40 PM Ralph Mellor <ralphdjmel...@gmail.com> wrote: > On Tue, Mar 5, 2024 at 7:01 AM ToddAndMargo via perl6-users > <perl6-users@perl.org> wrote: > > > >> $ raku -e '.say for <bk10 bk34 bk2 bk1>.sort(*.split(/\d+/, > :kv).map({ (try .Numeric) // $_}).List)' > > >> > > >> Yippee! > > > > raku -e '.say for <bk10 bk34 bk2 bk1>.sort: { .comb(/ \d+ | \D+ > /).map({ .Int // .self }).cache };' > > > > Awesome! Now I have two different methods! > > And now 4: > > $ raku -e '.say for <bk10 bk34 bk2 bk1>.sort: {m/ \d+ /.Int}' > bk1 > bk2 > bk10 > bk34 > > or, same logic, but spelled differently: > > $ raku -e '.say for <bk10 bk34 bk2 bk1>.sort: +*.match: / \d+ /' > bk1 > bk2 > bk10 > bk34 > > -- > love, raiph >