summaryrefslogtreecommitdiff
path: root/Chap7PracStrip.py
diff options
context:
space:
mode:
Diffstat (limited to 'Chap7PracStrip.py')
-rw-r--r--Chap7PracStrip.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Chap7PracStrip.py b/Chap7PracStrip.py
new file mode 100644
index 0000000..f17b2fb
--- /dev/null
+++ b/Chap7PracStrip.py
@@ -0,0 +1,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)