0

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.

Narek
  • 38,779
  • 79
  • 233
  • 389
  • 1
    A minor note is that it is usually considered a bad idea to process HTML using regular expressions. See for example http://stackoverflow.com/questions/2179477/best-way-to-parse-html-in-qt on how to parse HTML in Qt. – pafcu Dec 17 '10 at 15:07
  • This link is for parsing only, but I parse in order to edit, so I dont find convenient the method proposed in the question whose link is written above. May be there is a better aproach then the QRegExp but not this one. – Narek Dec 17 '10 at 15:16

3 Answers3

4

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

Community
  • 1
  • 1
Dave Mateer
  • 17,608
  • 15
  • 96
  • 149
2

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

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
Simone
  • 11,655
  • 1
  • 30
  • 43
0

What about :

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

Hope it helps !

Andy M
  • 5,945
  • 7
  • 51
  • 96