Re.findall() & Re.finditer()

  • + 34 comments

    The regexes I saw can be shortened using either a positive lookbehind or a positive lookahed. I don't think it can be solved without them because you have to avoid consuming the input somewhere (before or after).

    Using the positive lookbehind:

    import re
    v = "aeiou"
    c = "qwrtypsdfghjklzxcvbnm"
    m = re.findall(r"(?<=[%s])([%s]{2,})[%s]" % (c, v, c), input(), flags = re.I)
    print('\n'.join(m or ['-1']))
    

    Using the positive lookahead, same as above with the regex:

    [%s]([%s]{2,})(?=[%s])