[Qt-interest] Using QRegExp

Robert Hairgrove evorgriahr at hispeed.ch
Sun Mar 21 16:05:41 CET 2010


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!



More information about the Qt-interest-old mailing list