blob: f17b2fb6d1e8baebcd1518b97993ea8ab6db87a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#!python3
# Chap7PracStrip
# Remove whitespace from beginning and end of string using regex
import re
def remspace(string):
global stringrem
bspaceRegex = re.compile(r'\s*$')
fspaceRegex = re.compile(r'^\s*')
stringrem = bspaceRegex.sub('', string)
stringrem = fspaceRegex.sub('', stringrem)
return stringrem
remspace(' here is the string ')
print(stringrem)
|