[Qt-interest] Using QRegExp

BRM bm_witness at yahoo.com
Sun Mar 21 18:26:51 CET 2010


>From the 4.5.3 documentation under "Notes for Perl users:"

In QRegExp, apart from within character classes, ^ always 
signifies the start of the string, so carets must always be escaped 
unless used for that purpose. In Perl the meaning of caret varies 
automagically depending on where it occurs so escaping it is rarely 
necessary. The same applies to $ which in QRegExp always 
signifies the end of the string.

So, yes; it does seem that it can only be used for the start of a string. I ran into this a few weeks ago when trying to match up CDATA in XML.
I used RegExr (http://gskinner.com/RegExr/desktop/) to build regex, but it's more generalized than Qt's QRegExp. They had one to match HTML:

<[^<]+?>

So I based it on that; but Qt's QRegExp wouldn't match; the above quoted documentation explained why. I just needed to switch the usage of the ^ to (.*) to get what I needed.

HTH

Ben





----- Original Message ----
> From: Robert Hairgrove <evorgriahr at hispeed.ch>
> To: qt-interest at trolltech.com
> Sent: Sun, March 21, 2010 11:05:41 AM
> Subject: [Qt-interest] Using QRegExp
> 
> I'm trying to split up email headers into their corresponding fields 
using 
> regular expressions.

In a text editor which supports regular expression 
> search and replace 
(UltraEdit), I can use "^[\S]*:" as the regexp (for 
> QRegExp it would be 
"^[\\S]*:") and it matches all of the field names nicely 
> while ignoring 
the colons in the timestamps.

However, when I try to 
> use this same expression with QString::split(), 
it finds the first 
> occurrence (i.e. header field name) but ignores all 
the rest. The input is 
> the entire header which is contained in one 
QString object with embedded 
> newlines.

Does the "^" tag work only at the beginning of a string and not 
> after 
embedded newline characters? I suppose I could split the string at the 
> 
newline character and iterate over the resulting QStringList members, 
> 
but then I have to watch out for folded header lines (RFC 822 - 
> 
http://tools.ietf.org/html/rfc822 - at par. 3.4.8 on page 15 explains 
> 
about folded header fields).

Any advice here would be most 
> welcome!
_______________________________________________
Qt-interest 
> mailing list

> href="mailto:Qt-interest at trolltech.com">Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list