0
我想找到将带给我2或3个组的表达式,而第三组是可选的(可以或不可以)
这里是我使用的表达式远:如何使正则表达式捕获可选组
var expr = /^\s*(.+)\s+in\s+(.*?)\s*$/
如果用户只具有“物联网的东西” - 我想匹配阵列是如下:
[1] - thing
[2] - Things
如果用户拥有“的东西在物联网|排序依据 “身份证”” - 我想匹配阵列是如下:
[1] - thing
[2] - Things
[3] - | orderBy "id"
console.log('2:'+'thing in Things'.match(expr)[2]) //-want it to be "Things"
console.log('3:'+'thing in Things | orderBy "id"'.match(expr)[3]) //want it to be 'orderBy "id"'' (currently - undefined)
这里是链接到jsbin该发现证明问题:
感谢前锋
你的意思是你想用'in'和'|'来分割字符串吗? – Passerby