Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript缩小文件上的Regexp最小匹配_Javascript_Regex - Fatal编程技术网

javascript缩小文件上的Regexp最小匹配

javascript缩小文件上的Regexp最小匹配,javascript,regex,Javascript,Regex,我有一个缩小的文件。主要的特殊性是只有一条线 这可能是一个摘录: bla();someothercode('resources/images/myPicture1.png'),someothercode('resources/images/myPicture2.png'),someothercode('resources/images/myPicture3.png');plop(); 我试着用/\/(.*\.png)捕捉,我得到了: myPicture1.png'),someothercode

我有一个缩小的文件。主要的特殊性是只有一条线

这可能是一个摘录:

bla();someothercode('resources/images/myPicture1.png'),someothercode('resources/images/myPicture2.png'),someothercode('resources/images/myPicture3.png');plop();
我试着用
/\/(.*\.png)
捕捉,我得到了:

myPicture1.png'),someothercode('resources/images/myPicture2.png'),someothercode('resources/images/myPicture3.png
而不是许多结果:

[myPicture1.png, myPicture2.png, myPicture3.png]

如何分别匹配所有PNG?

使用以下正则表达式:

\/([^\/]*\.png)
在这里,
\/
匹配
/
,然后
([^\/]*\.png)
匹配并捕获png的名称(因为
[^\/]*
匹配0个或更多字符而不是
/
,返回的匹配结果与预期一致,预期值位于组1内)

见代码:

var re=/\/([^\/]*\.png)/g;
var str='bla();someothercode(\'resources/images/myPicture1.png\')、someothercode(\'resources/images/myPicture2.png\')、someothercode(\'resources/images/myPicture3.png\');扑通一声();
var-m;
while((m=re.exec(str))!==null){
文件。写(m[1]+“
”);
}
使用以下正则表达式:

\/([^\/]*\.png)
在这里,
\/
匹配
/
,然后
([^\/]*\.png)
匹配并捕获png的名称(因为
[^\/]*
匹配0个或更多字符而不是
/
,返回的匹配结果与预期一致,预期值位于组1内)

见代码:

var re=/\/([^\/]*\.png)/g;
var str='bla();someothercode(\'resources/images/myPicture1.png\')、someothercode(\'resources/images/myPicture2.png\')、someothercode(\'resources/images/myPicture3.png\');扑通一声();
var-m;
while((m=re.exec(str))!==null){
文件。写(m[1]+“
”); }
要捕获以
.png
结尾的所有“单词”,您可以说:

/\b[^\/]+\.png/g
这将查找文件名,无论前面是否有
/

var st=“bla();someothercode('resources/images/myPicture1.png')、someothercode('resources/images/myPicture2.png')、someothercode('resources/images/myPicture3.png');plop();”;
var matches=st.match(/\b[^\/]+\.png/g);
console.log(匹配项)
要捕获以
.png
结尾的所有“单词”,您可以说:

/\b[^\/]+\.png/g
这将查找文件名,无论前面是否有
/

var st=“bla();someothercode('resources/images/myPicture1.png')、someothercode('resources/images/myPicture2.png')、someothercode('resources/images/myPicture3.png');plop();”;
var matches=st.match(/\b[^\/]+\.png/g);

console.log(匹配项)
*?
-非贪婪匹配。
*?
不起作用。我也没有得到反对票。。。无论如何,已经很少有好的答案。
*?
-不贪婪的匹配。
*?
不起作用。我也没有得到反对票。。。无论如何,已经没有什么好的答案了。