I am trying to find a range of numbers within a string. The different ranges are listed below. How can I search a specific range of number?
Ensure the first number is between [1, 17], the second between [1, 37], etc.
import re
Test1 = "This is a test 5-9-81-15"
A1 = range(1, 17)
A2 = range(1, 37)
A3 = range(76, 89)
A4 = range(13, 27)
x = re.search("{0}-{1}-{2}-{3}".format(A1, A2, A3, A4), Test1)
if x:
print ("Match")
else:
print ("No Match")
If you can get a string of just the numbers, here is how you might check to see if it fits your requirement:
An example that fails:
Regular expressions is the right tool if you need to extract the digit sequence from a larger string that has other text/characters in it.