import re
regex = re.compile(r"^(-?(\d*\.)?\d+)((px)|(em)|(%)|(ex)|(ch)|(rem)|(vw)|(vh)|(vmin)|(vmax)|(cm)|(mm)|(in)|(pt)|(pc))$", flags=re.MULTILINE | re.IGNORECASE)
test_str = ("23px\n"
"3.32423423cm\n"
".87687533mm\n"
"34223423em\n"
"23423423%\n"
"234ex\n"
"67ch\n"
"4535rem\n"
"1vw\n"
"435345vh\n"
"3.456456vmin\n"
"23424234.23423423px\n"
"0.3vmax\n"
"1pt\n"
"435345pc\n"
"3.456456in\n\n"
"-23px\n"
"-3.32423423cm\n"
"-.87687533mm\n"
"-34223423em\n"
"-23423423%\n"
"-234ex\n"
"-67ch\n"
"-4535rem\n"
"-1vw\n"
"-435345vh\n"
"-3.456456vmin\n"
"-23424234.23423423px\n"
"-0.3vmax\n"
"-1pt\n"
"-435345pc\n"
"-3.456456in\n"
"-1vw\n"
"-3.456456vmin")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html