Jump to content
  • Advertisement
Sign in to follow this  
y2jsave

QRegExp doubt !

This topic is 2770 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!