summaryrefslogtreecommitdiff
path: root/Chap7PracStrip.py
diff options
context:
space:
mode:
authormlot <petri-rush-curvy@duck.com>2025-06-06 13:40:57 -0400
committermlot <petri-rush-curvy@duck.com>2025-06-06 13:40:57 -0400
commit75a42ec54dbf721caa659ddf02c1f46fc2cb4bef (patch)
tree84be794a2481e356a7784557a6f9fb6fbf29cfdd /Chap7PracStrip.py
initial commit for archivingHEADmain
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)