📜  从字符串 python 中提取带有 serten lenth 的数字 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:28.311000             🧑  作者: Mango

代码示例1
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\n',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\n',finalx)