Percentage in PY
Matches percentage values with optional decimal and a trailing % sign.
Try it in the PY tester →Pattern
regexPY
^\d+(\.\d+)?%$Python (re) code
pyPython
import re
pattern = re.compile(r"^\d+(\.\d+)?%$")
input_text = "95%"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
How the pattern works
`^\d+` matches integer part. `(\.\d+)?` optional decimals. `%$` requires a trailing percent sign at end.
Examples
Input
95%Matches
95%
Input
99.9%Matches
99.9%
Input
100No match
—