linfo2335-programming-parad.../project-3/regex/flaw_3.py

21 lines
384 B
Python

import re
def detect_unused_loop_variable(code):
regex = re.compile(
r"^(?P<indent> *)for (?P<id>\S+) in .+:(?:\n(?P=indent) +((?P<contains>[^#\n]*(?P=id).*)|.*))*",
re.MULTILINE,
)
result = regex.search(code)
if not result:
return False
if result.group("contains"):
return False
# print(result.group(0))
return True