Remove spaces regex


This is not necessary as we can use rstrip, lstrip, and replace.


examples/regex/remove_spaces_regex.py
import re

line = "  ab cd  "

res = re.sub(r'^\s+', '', line)  # leading
print(f"'{res}'")

res = re.sub(r'\s+$', '', line)  # trailing
print(f"'{res}'")

both ends:


re.sub(r'\s*(.*)\s*$', r'\1', line)  #  " abc " =>  "abc "  because of the greediness


re.sub('^\s*(.*?)\s*$', '\1', line)  #   " abc " =>  "abc"  minimal match