-
Notifications
You must be signed in to change notification settings - Fork 6
/
regular expressions.py
51 lines (34 loc) · 1.47 KB
/
regular expressions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import re
# Q.2 Retrieve all the words starting with ‘b’ or ‘B’ from the following text.
'''
a= ("Betty bought a bit of butter, But the butter was so bitter, So she bought some better butter, To make the bitter butter better.")
a=a.replace("Betty","betty")
a=re.findall(r'b[\w]*',a)
print(a)
'''
# Q.3- Split the following irregular sentence into words sentence = "A, very very; irregular_sentence" desired_output = "A very very irregular sentence"
'''
a=(" \" A, very very; irregular_sentence \" ")
a=a.replace(",","")
a=a.replace(";","")
a=a.replace("_"," ")
print(a)
'''
#Q.4- Clean up the following tweet so that it contains only the user’s message. That is, remove all URLs, hashtags, mentions, punctuations, RTs and CCs.
'''
a=(" \' Good advice! RT @TheNextWeb: What I would do differently if I was learning to code today \' http://t.co/lbwej0pxOd cc: @garybernhardt #rstats")
a=a.replace("http://t.co/lbwej0pxOd cc: @garybernhardt #rstats", "")
a=a.replace("! RT @TheNextWeb:","")
print(a)
'''
#Q1 Extract the user id, domain name and suffix from the following email addresses.
#emails = "zuck26@facebook.com" "page33@google.com" "jeff42@amazon.com"
#desired_output = [('zuck26', 'facebook', 'com'), ('page33', 'google', 'com'), ('jeff42', 'amazon', 'com')
'''
a= ["zuck26@facebook.com", "page33@google.com", "jeff42@amazon.com"]
z=[]
for e in a:
z.append(tuple(re.split('[@.]',e)))
print(z)
'''
#END ASSIGNMENT