用于解析带有参数的HTML中的img标记的正则表达式


regex for parsing a img tag in html with parameters

我有这种用于在我的博客上发布内容的标记语言,我使用以下行来解析图像

$$link_to_image width height alternative_description$$

我用下面的php句子解析这个

preg_replace('/'$'$(.*?)'s'd+'s'd+'s(.*?)'$'$/','<img src = "''1" width = "''2px" height = "''3px" alt = "''4" >',$this->text);

,其中$this->text是博客文章的全文。

问题是当我输入类似的东西时$$http://s15.postimg.org/60dod0gu3/input.png 400 300 Raw data$$我得到

<img src="http://s15.postimg.org/60dod0gu3/input.png" width="Raw datapx" height="px" alt="">

我写的正则表达式有什么问题?

你只捕获2组,但你想要4。为数字再添加两个捕获组:

'$'$(.*?)'s('d+)'s('d+)'s(.*?)'$'$

演示。