输入:parent/123/child/grand-child
预期输出:child
尝试1:(?<=\/parent\/\d*)(.*)(?=\/.*)
错误:lookbehind内部的量词使它的宽度不固定,look back不接受*,但我不知道该数字的宽度,因此必须使用它]]
尝试2:
(有效但有2个衬里):const currentRoute='/parent/123/child/grand-child' let extract = currentRoute.replace(/\/parent\/\d*/g, ''); extract = extract.substring(1, extract.lastIndexOf('/')); console.log('Result', extract)
如何使用一个衬管(最好使用正则表达式)获得提取物>>
输入:parent / 123 / child / grand-child预期输出:child尝试1:(?<= \ / parent \ / \ d *)(。*)(?= \ /.*)错误:内部有一个量词后向使其不固定宽度,后向不...
怎么样
currentRoute.match(/\/parent\/(?:.*)\/(.*)\//)[1]