[Qt-interest] Problem with QRegExp
Alexandre Beraud
aberaud at infflux.com
Tue Feb 10 15:49:11 CET 2009
Hi,
If you use QRegExp::Wildcard then you can not use the regex syntax, but
only wildcards like ? or *. Moreover, ^ and $ mark respectively the
beginning and the end of the string. Thus, ^(\s+) looks for a string
starting with at least one space (but your string starts with 'ii').
Finally, exactMatch does not need the ^ and $ assertions. If you need
to know if your string contains the pattern, just use the contains() method:
if (tmp.contains("debhelper")) {...}
If you really need to capture the number of spaces (do you really need
it ??), then try:
QRegExp rx("(\\s+)debhelper");
if (tmp.contains(rx)) {QString spaces = rx.cap(1);}
Regards,
Alex
Jan Dinger a écrit :
> Hello folks,
>
> i've problem to find a string in QString.
>
> Hiere is my QString:
> ### snip ###
> QString tmp = "ii debhelper 7.0.15
> helper programs for debian/rules";
> ### snap ###
>
> Now, I'll search for "debhelper".
>
> Here is my construction to search for "debhelper".
>
> ### snip ###
> QRegExp rx("^(\\s+)debhelper$");
> rx.setPatternSyntax(QRegExp::Wildcard);
>
> if (rx.exactMatch(tmp))
> qDebug() << "string includes debhelper";
> ### snap ###
>
> The construction can't find debhelper in the string, can someone tell
> me how must I build the QRegExp correctly?
>
> Thanks for help.
>
> so long
> jd
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
>
--
BERAUD Alexandre
Ingénieur Développement
Infflux - Informatique & Flux
Tel: 01 49 57 92 00 - Fax : 01 49 57 92 01
Mail: aberaud at infflux.com
Visitez notre site : www.infflux.com
More information about the Qt-interest-old
mailing list