i am trying to extract the phone but the expression returns none. here is my code.it must start with 9 and end with number with only number inbetween.
line='my phone is 98849448470'
matchnum=re.search(r"^9[0-9]*[0-9]$",line)
print(matchnum)
i am trying to extract the phone but the expression returns none. here is my code.it must start with 9 and end with number with only number inbetween.
line='my phone is 98849448470'
matchnum=re.search(r"^9[0-9]*[0-9]$",line)
print(matchnum)
matchnum=re.search(r"^9[0-9]*[0-9]$",line)
The ^
at the start and $
at the end force the expression to try to match the entire line
. However, your actual line
contains other stuff besides what you want to search for. So leave those out.
Also, instead of [0-9]*[0-9]
for one or more matches, we can simply use [0-9]+
.