[Qt-interest] Using QRegExp

Robert Hairgrove evorgriahr at hispeed.ch
Sun Mar 21 16:58:14 CET 2010


Robert Hairgrove wrote:
> I'm trying to split up email headers into their corresponding fields 
> using regular expressions.
[snip]

OK, this DOES seem to be the case, i.e. the caret "^" matches the 
beginning of the STRING and not the beginning of a new LINE if the 
string contains embedded new line characters. The same appears to hold 
true for the "$" (end-of-line). Although the docs do say as much, it is 
not entirely intuitive because there must be many users who assume (as I 
did) that it works on lines.

So I got it to work using the following, treating the first header field 
as a special case:

     QRegExp rx1("^[\\S]*:");
     QRegExp rx2("\\n[\\S]*:");

then followed the example using rx2.matchedLength() to build up an index 
into the data, then constructed the QStringList using QString::mid() 
with the index data.



More information about the Qt-interest-old mailing list