Group(), Groups() & Groupdict()

  • + 1 comment

    You can use re.match, that's not the problem. The problem is if you are using \w, because Python counts underscores and this problem does not.

    import re
    S=input()
    #print(S)
    m=re.match(r'.*?([a-z0-9A-Z])\1', S)
    if m is None:
        print(str(-1))
    else:
        print(m.group(1))