I'm performing a regex search in python like the one below:
import re
regexSearch = re.search(r'FTP-exception-sources-\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', line, re.M|re.I )
if regexSearch:
outputFile2.write(str(lineCounter) + " , " + regexSearch.group(0) + "\n")
How can I determine the number of groups
that get returned from the regex search?
regexSearch.groups()
is all of the groups. len(regexSearch.groups())
gets the count.
In your case there will always be 0 groups as your regex does not contain groups (group(0)
is the whole match and not really a group)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With