문제

I have written

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

RegExp 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.

도움이 되었습니까?

해결책

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

다른 팁

\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.

What about :

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

Hope it helps !

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top