[Interest] QRegExp exclamation marks

Bo Thorsen bthorsen at ics.com
Mon May 27 18:17:38 CEST 2013


Den 27-05-2013 16:48, Sensei skrev:
> Hi all, this is quite simple, I hope!
>
> I am trying to use the regexp application to find all patterns I need
> before coding. Now, I'd like to match full words that have this patterns:
>
>
> ! This is the text
>
> PROGRAM WARNING: This is the text
>
>
> I've come with the following:
>
> QRegExp r("PROGRAM WARNING|!\\s");
>
>
> and it matches strings like:
>
> ! What is this?  ==> index 0, length 2
> PROGRAM WARNING: some text ==> index 0, length 15
>
>
> I would like to match just full patterns, but I fail to make a valid
> QRegExp behave like I'd like, like this one
>
>
> QRegExp r("\\b(PROGRAM WARNING|!\\s)");
>
>
> it matches just the second line, not the "! " patterns.
>
> What do you suggest?

When I do regular expressions for complete lines, I use something like this:

QRegExp r("^(PROGRAM WARNING|!\\s+)(.*)$");

r.cap(1) should be the first part, which you don't need. r.cap(2) should 
be the text you are interested in.

Bo.

-- 
Bo Thorsen, European Qt Manager, Integrated Computer Solutions
ICS - Delivering World-Class Applications for Embedded & Mobile Devices
http://ics.com/services



More information about the Interest mailing list