Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

extract digits with serten lenth from string python

import re

str = 'We four guys, live at 2nd street of Malibeu 521. I had a cash of $248 in my pocket. I got a ticket with serial number 88796451-52.'

#search using regex
x = re.findall('[0-9]+', str)
print('All Numbers
',x)

#digits of length N
N=3

def filterNumber(n):
	if(len(n)==N):
		return True
	else:
		return False
		
#filter the list
finalx = list(filter(filterNumber, x))
print('Final List
',finalx)
Source by pythonexamples.org #
 
PREVIOUS NEXT
Tagged: #extract #digits #serten #lenth #string #python
ADD COMMENT
Topic
Name
3+5 =