我想從字符串中提取5個連續數字正則表達式匹配不包含數字的5位子字符串
我寫的代碼。
re.findall(r"((\D|^)*)\d\d\d\d\d((\D|$)*)", s)
但它不能傳遞字符串
"Helpdesk-Agenten (m/w) Kennziffer: 12966"
預期的結果是:
12966
實施例2:
#input
"Helpdesk-Agenten (m/w) Kennziffer: 12966abc"
# expected
12966
實施例3:
#input
"Helpdesk-Agenten (m/w) Kennziffer: 12966345"
# expected
"" (because the length of continuous digits is longer than 5)
也許你可以提供更多的比賽例子?它應該匹配12345abc嗎? –
@讓FrançoisFabre感謝您的意見,增加了兩個例子 –
這裏是另一個類似的問題http://stackoverflow.com/questions/16348538/python-regex-for-int-with-at-least-4-digits – Kasramvd