我有一个包含以下值的数组
asd sdf dsdf 1sadf *sdf !sdf @asdf _asd .sadf (sadf )sadf #sadf
^asdf &asdf %asdf -sadf =sadf +sadf -sdf
Run Code Online (Sandbox Code Playgroud)
我想通过以下方式将其在javascript中排序为三个部分.
所以这应该是排序数组的序列.
编辑:这是我一直在尝试的功能:
function naturalSort(a, b) {
a = a.path.toLowerCase();
b = b.path.toLowerCase();
var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
sre = /(^[ ]*|[ ]*|[_]*$)/g,
dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
hre = /^0x[0-9a-f]+$/i,
ore = /^0/,
// convert all to strings and trim()
x = a.toString().replace(sre, '') || '',
y = b.toString().replace(sre, '') …Run Code Online (Sandbox Code Playgroud)