Try to search your question here, if you can't find : Ask Any Question Now ?

getting zip code plus four digits using regex

HomeCategory: stackoverflowgetting zip code plus four digits using regex
Avatarpragati asked 1 week ago
import re
s = '92675-2042 BL-17-1111, 18S-8 01345-1345 L1-12 23345-0921 45312-8733 21-year old, 40-year-old, 67-years, BL-14-111, 91-years, AL-1-2, 01-13-2019, 1-22-2001'
reg = r'\b\d{5}(?:[ -]\d{4})?\b'
r1 = re.findall(reg,s)

I have the following reg taken from Extract 5 digit zip code from string that returns an empty list []. I want reg to get all the zip codes in s plus four digits attached to them e.g '92675-2042'. I would like my output to be

 ['92675-2042', '01345-1345', '23345-0921', '45312-8733']

How do I tweak reg = r'\b\d{5}(?:[ -]\d{4})?\b' to get my desired output?

1 Answers
Best Answer
AvatarArben answered 1 week ago
Your Answer

19 + 19 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com