Possible Duplicate:
Non capturing group?
I’m learning regex in JavaScript, and the (?:x) character or “non-capturing parentheses” just doesn’t make sense to me. If you don’t want the match to be remembered why not just abandon parentheses altogether? What’s the advantage of using /(?:x)/ instead of just /x/?
Because you might need the parentheses for other reasons. For example, suppose you want to capture the digit at the end of
abababababab9. If you wroteab*(\d)then it would matchabbbbbbbbb9. You need to parenthesize theabso that the*operator will repeat the whole thing.(ab)*(\d). But maybe you don’t care about how many timesabwas repeated. That’s where you use(?:):(?:ab)*(\d).