Non-capturing group vs named group | SoloLearn: Learn to code for FREE!


Non-capturing group vs named group

Why would one use a named non-capturing group rather than a named group? The example gives ?:def but I fail to see how this is a better way of doing it rather than giving it a name such as <first>

1/14/2017 9:23:48 PM

Matt B

3 Answers

New Answer


Never mind, looked at tut comments.


Just remember that the method groups() returns all groups up from 1


import re num = "07987549836" pattern = r"9" num = re.sub(pattern, "0", num) print(num)