正则提取字符串
a1 file="block/header.html"
b file = "block/header.html"
c1 file='block/header.html'
dd file="block/top/header.html"
我想得到引号之间的文件路径字符串,我的正则是这样写的
file( )?=("|')?((\w+)\/)+(\w+).html("|')?
但这样匹配出来的结果是
file="block/header.html"
file = "block/header.html"
file='block/header.html'
file="block/top/header.html"
还是没有办法得到后面的文件路径字符串
block/header.html
block/header.html
block/header.html
block/top/header.html
要想得到这些文件路径字符串,正则应该如何写?
正则
------解决方案--------------------var str = 'a1 file="block/header1.html" "as123123\'rtetr3234234\'dasd"b file = "block/header2.html"c1 file=\'block/header.html\'dd file="block/top/header.html"';
var reg = /file\s*=\s*(?:\"
------解决方案--------------------
\')([^"']*)(?:\"
------解决方案--------------------
\')/g;
var result = [];
str.replace(reg,function(block,str){
result.push(str)
})
console.log(result)