-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreg_exp.py
More file actions
44 lines (34 loc) · 841 Bytes
/
Copy pathreg_exp.py
File metadata and controls
44 lines (34 loc) · 841 Bytes
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
#This header file contains regular expression which makes extraction of a desired strings from a collection easy
import re
#Opening a text file with sample code
cool = open("reg_exp.txt")
#This is use of just one regular expression
'''
for line in cool:
line = line.rstrip()
if re.search(":",line):
print 'a ->' + line
if re.search("^:",line):
print 'b ->' + line
if re.search(":$",line):
print 'c ->' + line
'''
#This is use of combination of regular expressions
'''
for line in cool:
line = line.rstrip()
if re.search("^X.*:$",line):
print "a ->" + line
if re.search("^X\S+:.*:$",line):
print "b ->" + line
'''
#This makes use of square brackets for string
"""
for line in cool:
# y is collection of digit values in th line
y = re.findall("[0-8]+",line)
print y
"""
y = "Xmas sucks"
for x in y:
print "Merry"