" Sample".lstrip()
The reason that lstrip
is prefereable is that there are any number of hidden (or unprintable) characters. To get a regular expressions to capture all the purmutations is a little messy display wise. Clear code is the best code.
There is the option of using POSIX character classes within your regex, however the re
module does not seem to support them at this time. You will have to use a different module that supports the POSIX classes (regex 0.1.20120323
).
(Note: Newly registered so I could not 'post more than 2 hyperlinks'.)
References:
docs.python.org/library/string.html
"If chars is omitted or None, whitespace characters are removed."
stackoverflow.com/questions/9897375/how-to-match-a-space-at-the-beginning-of-the-expression-python
"POSIX character classes ... [:space:] \s \s [ \t\r\n\v\f] Whitespace characters"
pypi.python.org/pypi/regex
"POSIX character classes are supported. This is actually treated as an alternative form of \p{...}."
http://pypi.python.org/pypi/regex
"Alternative regular expression module, to replace re."