• Advertisement
Sign in to follow this  

QRegExp doubt !

This topic is 2559 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

QRegExp rxp;

case1 :: rxp.setPattern(val);
case2 :: rxp.setPattern("^" + val + "$");




suppose val is [cc dd]

now if my input string to be matched is dd , it matches in case1 but not in case2 ..

can someone tell why >>

thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
I don't know QRegExp, but I will assume it follows the same regex rules as Perl (or close to it). Apologies if it what I say is not correct.

Anyway, when you use brackets '[]', it only matches a single literal character in the brace. So val = [cc dd] means, "match a 'c', a 'd', or a space".

This works in the first case, because it says "oh, I see a single d, I match".

In the second case, you're saying "there must be one and only one character between the start and end, either c, d, or space, which isn't true for "dd".

If you want to match "cc" or "dd", you want something like this: val = (cc|dd)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement