开发者

QRegExp problem

I have written

QRegExp rx("<img src=\"\\S+\"\\s+width=\"(\\d+)\"\\s+height\"(\\d+)\"\\s+/>");

Reg开发者_如何转开发Exp in order to match

 <img src="file://c/Users/Narek/Desktop/WClub.jpg" width="95" height="113.04" />

kind of substring in a string, in order to extract the width and height. But this does not match. Please tel me what I have done wrong.


\d does not match the period in your height.

A regular expression that would work would be something like:

<img src=\"[^"]*\"\s+width=\"(\d+(?:\.\d+)?)\"\s+height=\"(\d+(?:\.\d+)?)\"\s+/>

Also, the obligatory comment that it is a bad idea to parse HTML using Regex.


The last \d doesn't take account of the dot inside the number, and you are missing '=' after 'height'.


What about :

QRexExp rx("<img src=[^<]+/\> ");

Hope it helps !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜