[SOLVED] QRegExp exept capture group



  • Hi All, i have regexp like this:
    @%(\d+)(\s*:\s*(\w))(\s,\s*(\d+))*@
    and i don't need 2nd and 4th captured field, can i except that fields from regexp? (maybe need write some magic symbol before opened bracket)



  • The solution is the help on QRegExp :)

    bq.
    If we want to use parentheses purely for grouping and not for capturing we can use the non-capturing syntax, e.g. (?:green|blue). Non-capturing parentheses begin '(?:' and end ')'. In this example we match either 'green' or 'blue' but we do not capture the match so we only know whether or not we matched but not which color we actually found. Using non-capturing parentheses is more efficient than using capturing parentheses since the regexp engine has to do less book-keeping.

    Concretely:

    @%(\d+)(?:\s*:\s*(\w))(?:\s,\s*(\d+))*



  • @%(\d+)(?:\s*:\s*(\w))(?:\s,\s*(\d+))*@



  • tnx a lot!
    Don't read to that paragraph, i remember so need write some symbol, but what exactly - can't remember. :(


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.