substitute a pattern only if it appears at the beginning of a string.
for e.g. str1 = "abab abadfadsf"
I only want to remove/replace the “ab” at the beginning of str1, i.e. I want to write an regex so that I can get str2 = "ab abadfadsf" from str1 by re.sub
how do I do it?
You can use
re.sub('^ab', '', 'abab abadfadsf')^stands for the beginning of the string.