From 75a42ec54dbf721caa659ddf02c1f46fc2cb4bef Mon Sep 17 00:00:00 2001 From: mlot Date: Fri, 6 Jun 2025 13:40:57 -0400 Subject: initial commit for archiving --- Chap7PracStrip.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Chap7PracStrip.py (limited to 'Chap7PracStrip.py') 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) -- cgit