I need to check the specific sorting. There is list of classes:
[
no = '1'
field = 'FEE_HIG_R_test1234_2',
no = '2'
field = 'FEE_HIG_R_test1234_11',
no = '3'
field = 'FEE_HIG_R_test1234_10',
no = '4'
field = 'FEE_HIG_R_test1234_1',
no = '5'
field = '06633-146944-0000036012',
no = '6'
field = '06633-155867-0000051910',
no = '7'
field = '06687-250844-00002544203'
]
I have to sort by field in alphanumeric based on numbers and get the result like:
[
no = '5'
field = '06633-146944-0000036012',
no = '6'
field = '06633-155867-0000051910',
no = '7'
field = '06687-250844-00002544203',
no = '4'
field = 'FEE_HIG_R_test1234_1',
no = '1'
field = 'FEE_HIG_R_test1234_2',
no = '3'
field = 'FEE_HIG_R_test1234_10',
no = '2'
field = 'FEE_HIG_R_test1234_11'
]
I tried: result.sort{ a,b -> (((a.field =~ /\d+/)[-1] as Integer) <=> ((b.field =~ /\d+/)[-1] as Integer)) }
but result was:
[
no = '4'
field = 'FEE_HIG_R_test1234_1',
no = '1'
field = 'FEE_HIG_R_test1234_2',
no = '3'
field = 'FEE_HIG_R_test1234_10',
no = '2'
field = 'FEE_HIG_R_test1234_11',
no = '5'
field = '06633-146944-0000036012',
no = '6'
field = '06633-155867-0000051910',
no = '7'
field = '06687-250844-00002544203'
]
Could someone help?
Something like this one-liner:
The
1000000... +is needed to push the smaller numbers in strings likeFEE_HIG_R_test1234_1further to the right.