简体   繁体   English

正则表达式在后台url标签内查找值

[英]Regex to find value inside background url tag

  1. I have "$('#tab1').css("background-image", "url(../CARImages/Icons/tab1.png)");" 我有"$('#tab1').css("background-image", "url(../CARImages/Icons/tab1.png)");" I need to extract "../CARImages/Icons/tab1.png" from this. 我需要从中提取"../CARImages/Icons/tab1.png"

  2. I may have "background-image:url(../Images/Themes/tile_bg.png);" 我可能有"background-image:url(../Images/Themes/tile_bg.png);" syntax in css. CSS中的语法。 I need to extract "../Images/Themes/tile_bg.png" from this. 我需要从中提取"../Images/Themes/tile_bg.png"

Can I have same Regex for both the above syntax to extract image reference. 我可以为上述两种语法使用相同的Regex提取图像参考吗?

Use the regex (?<=url\\().*?(?=\\)) . 使用正则表达式(?<=url\\().*?(?=\\)) It will match text between the first url( in the string and the first ) after that. 它将在此后的第一个url(字符串中的第一个)之间匹配文本。

You can find an explanation and demonstration here: http://regex101.com/r/qP9mX6 您可以在此处找到说明和演示: http : //regex101.com/r/qP9mX6

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM