diff options
author | mlot <petri-rush-curvy@duck.com> | 2025-06-06 13:40:57 -0400 |
---|---|---|
committer | mlot <petri-rush-curvy@duck.com> | 2025-06-06 13:40:57 -0400 |
commit | 75a42ec54dbf721caa659ddf02c1f46fc2cb4bef (patch) | |
tree | 84be794a2481e356a7784557a6f9fb6fbf29cfdd /Chap7PracStrip.py |
Diffstat (limited to 'Chap7PracStrip.py')
-rw-r--r-- | Chap7PracStrip.py | 16 |
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) |