I am getting my data from XML which may some time contain special Character at beginning like:
'This is a sample title or %&*I don't know if this is the text
I tried with :
title[0].isstring() or title[0].isdigit() and then remove the character.  But if there are more than one special character at the beginning, then how do I remove it? Do I need a for loop?
You could use a regular expression:
import re
mystring = re.sub(r"^\W+", "", mystring)
This removes all non-alphanumeric characters from the start of your string:
Explanation:
^   # Start of string
\W+ # One or more non-alphanumeric characters
                        >>> import re
>>> re.sub(r'^\W*', '', "%&*I don't know if this is the text")
"I don't know if this is the text"
#or
>>> "%&*I don't know if this is the text".lstrip("!@#$%^&*()")
"I don't know if this is the text"
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With