I have a list of strings containing arbitary phone numbers in python. The extension is an optional part.
st =
My objective is to segregate the phone numbers so that I can... moreI have a list of strings containing arbitary phone numbers in python. The extension is an optional part.
st =
My objective is to segregate the phone numbers so that I can isolate each individual group viz. '800', '555', '1212' and the optional '1234'.
I have tried out the following code.
p1 = re.compile(r'(\d{3}).*(\d{3}).*(\d{4}).*(\d{4})?')
step1 =
p2 = re.compile(r'(\d{3})(\d{3})(\d{4})(\d{4})?')
step2 =
p1 and p2 being the two patterns to fetch the desired output.
for i in range(len(step2)):
print step2
Since I am a newbie, I wish to get suggestions if there are better ways to tacle such problems or some best practices followed in Python community. Thanks in advance.
I'm taking this course on Coursera, and I'm running some issues while doing the first assignment. The task is to basically use regular expression to get certain values from the... moreI'm taking this course on Coursera, and I'm running some issues while doing the first assignment. The task is to basically use regular expression to get certain values from the given file. Then, the function should output a dictionary containing these values:
example_dict = {"host":"146.204.224.152",
"user_name":"feest6811",
"time":"21/Jun/2019:15:45:24 -0700",
"request":"POST /incentivize HTTP/1.1"}
This is just a screenshot of the file. Due to some reasons, the link doesn't work if it's not open directly from Coursera. I apologize in advance for the bad formatting. One thing I must point out is that for some cases, as you can see in the first example, there's no username. Instead '-' is used.
159.253.153.40 - - "POST /e-business HTTP/1.0" 504 19845
136.195.158.6 - feeney9464 "HEAD /open-source/markets HTTP/2.0" 204 21149
This is what I currently have right now. However, the output is None. I guess there's something wrong in my... less