PDA

View Full Version : Quick RegExp question



stealth86
25th July 2007, 22:42
I'm using QRegExp and I want to parse resolution strings for the width and height.

IE "640x480" should be parsed into two strings "640" and "480".

I thought I could do this with capturedTexts(), but it works differently than I expected. Anyways, there must be an easy way to do this and I'm just not seeing it.

This is what I wrote, which after reading the documentation will not of course do what I was hoping.


QRegExp RegExp( "\\d+" );
QStringList StringList;

RegExp.indexIn( strResolution );

StringList = RegExp.capturedTexts();

Lykurg
25th July 2007, 22:54
QRegExp RegExp( "\\d+" );

Do you have forgot the brackets?

QRegExp RegExp( "(\\d+)" );

Lykurg

jacek
26th July 2007, 01:24
Try:
QRegExp RegExp( "(\\d+)x(\\d+)" );

fullmetalcoder
26th July 2007, 08:23
if your input is as simple as "width"x"height" then just use QString::split() it's both safer (no way the function fails if the delimiter is correct), simpler and faster. :)