I need help writing a regular expression to check strings whether they include a pattern like this: [xx.xx] where x can be any integer. (0-9)
Example:
-
Test [12.34]-> true -
Test [1234]->false
>Solution :
[0-9]{2} will match only two digits
\. will match one dot, use escape since . means in regex any character
import re
pattern = re.compile("^\[[0-9]{2}\.[0-9]{2}\]$")
print(bool(pattern.match("[12.34]")))#-> True
print(bool(pattern.match("[1234]")))#-> False