When to use capture groups

Hi, just wondering about when I need to used capture groups ( ). In this mission, I used the capture group in step 3 for finding the number of pythons without digits or periods.
pattern = "[Pp]ython ([\d\.]+)"

But in step 4 when I try to find the number of C’s without periods or pluses, I don’t use the capture group.
pattern = r"\b[Cc]\b[^.+]"

Not understanding why?

Screen Link: https://app.dataquest.io/m/369/advanced-regular-expressions/4/counting-mentions-of-the-c-language

1 Like

You use capturing group ( ) when you want to return only that part of the pattern. If that part of the pattern is enclosed by parentheses ( ) although the regex matches the entire pattern, it only returns this part. If you have multiple capture groups, the regex returns multiple results as can be seen in some of the exercises.


Ok thanks. Makes more sense.

1 Like

Hello @feedmyboxtoday,

Kindly mark the answer as the solution if you found @monorienaghogho’s reply satisfactory.
Check guideline 2 in this post to know how to mark a reply as a solution.

Happy Learning!