Narek
Narek

Reputation: 39881

QRegExp problem

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.

Upvotes: 0

Views: 828

Answers (3)

Simone
Simone

Reputation: 11797

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

Upvotes: 2

Dave Mateer
Dave Mateer

Reputation: 17956

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

Upvotes: 4

Andy M
Andy M

Reputation: 6065

What about :

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

Hope it helps !

Upvotes: 0

Related Questions