1## Remove the Starting Spaces in Python
2
3string1=" This is Test String to strip leading space"
4print (string1.lstrip())
5
1r = re.compile(r"^\s+", re.MULTILINE)
2r.sub("", "a\n b\n c") # "a\nb\nc"
3
4# or without compiling (only possible for Python 2.7+ because the flags option
5# didn't exist in earlier versions of re.sub)
6
7re.sub(r"^\s+", "", "a\n b\n c", flags = re.MULTILINE)
8
9# but mind that \s includes newlines:
10r.sub("", "a\n\n\n\n b\n c") # "a\nb\nc"