In python write a regular expression that exactly matches the numbers between 5000 and 9999
Python code:
import re
#defining regex to match numbers between 5000-9999
regex='[5-9][0-9][0-9][0-9]'
#obtaining number to test
num=input()
#checking for match
match=re.search(regex,num)
#checking if number is in range
if match:
#printing it
print("Number is in range")
else:
#printing Number is not in range
print("Number is not in range")
Screenshot:
Input and Output:
Get Answers For Free
Most questions answered within 1 hours.