大家好,我想从html中的一行获取图像名称。我正在用PHP做,例如我有以下几行
<img src="index_files/bottle2.jpg" name="product ds Grodsdwth" class="pullleft">
<img title="" src="index_files/ss-button.png" class="step-btn" alt=""></a>
我想要jus获取bottle2.jpg和ss button.png,并将其替换为{#CDNPath#}img/imageName以获取This Result
<img title="" src="{#CDNPath#}img/ss-button.png" class="step-btn" alt=""></a>
我有这个正则表达式,但它不起作用:
([a-z'-_0-9'/':'.]*'.(jpg|jpeg|png|gif))
我对这个逃脱和模式感到困惑,我会感谢你们
尝试使用此RegEx:
(<img.*?src=")((?:'w+'/)+?)(['w-]+'.(?:jpg|jpeg|png|gif))"
1st
捕获组存储打开的<img
和其他属性,然后存储src="
2nd
捕获组存储图像文件夹,即index_files/
或index_files/a/
3rd
捕获组存储图像名称
替换为:
$1{#CDNPath#}img/$3"
Regex101上的实时演示