我需要检查具体排序。有类列表:
[
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'
]
我必须根据数字按字母数字字段进行排序,并得到如下结果:
[
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'
]
我尝试了:result.sort{ a,B -〉(((a.field =~ /\d+/)[-1] as Integer)〈=〉((b.field =~ /\d+/)[-1] as Integer)))}
但结果是
[
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'
]
有人能帮忙吗?
1条答案
按热度按时间nbnkbykc1#
类似这样的一行代码:
需要
1000000... +
将字符串中较小的数字(如FEE_HIG_R_test1234_1
)进一步向右推。