Skip to content

Commit bc969e6

Browse files
committed
Strip()
Regular expression version of strip() built in function.
1 parent 8591e3b commit bc969e6

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

project3.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Regular expression version for strip() function
2+
3+
# If no arguments passed to strip() then remove whitespaces from beginning and end.
4+
5+
# Otherwise characters specified as second argument in strip() will be removed from the string
6+
7+
import re
8+
9+
string_in = raw_input("Enter the string")
10+
11+
char_rem = raw_input("Enter the character")
12+
13+
def regex_strip(string_in,char_rem):
14+
15+
a = re.compile(r'[%s]'%(char_rem))
16+
17+
# sub(pattern,replace,string,max=0)
18+
19+
return a.sub('',string_in)
20+
21+
print (regex_strip(string_in,char_rem))
22+
23+

0 commit comments

Comments
 (0)