Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.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 查找字符串中包含正则表达式的所有后台URL_Javascript_Regex - Fatal编程技术网

Javascript 查找字符串中包含正则表达式的所有后台URL

Javascript 查找字符串中包含正则表达式的所有后台URL,javascript,regex,Javascript,Regex,我有一个字符串,它有以下内容: <div style="background-image:url(some src); background-color:some color;"> <div style="background-image:url(some src); background-color:some color;"> </div> </div> 我需要找到这个字符串中的所有背景图像URL。现在我有以下正则表达式:/back

我有一个字符串,它有以下内容:

<div style="background-image:url(some src); background-color:some color;">
   <div style="background-image:url(some src); background-color:some color;">  </div>
</div>

我需要找到这个字符串中的所有背景图像URL。现在我有以下正则表达式:
/background image.*[);]/g

但它采用背景图像和背景颜色,只出现一次而不是两次。

RegEx解决方案: 用以下内容替换您的正则表达式:

/(background-image.*?(?:;))/g
  • /(
    分隔符和捕获组
  • 背景图像
    匹配字符串中的相同内容
  • *?
    匹配任何字符(换行符除外)
  • (?:
    非捕获组
  • 匹配字符;按字面意思
  • g
    (修饰符)全局。所有匹配项(第一次匹配时不返回)

var-str='\
\
';
var result=/(背景图像。*?(?:;)/g.exec(str);
编写(结果[0]+“
”); 文档。写入(结果[1]);