pattern = r'[ -\\[\\]]'
regex = re.compile(pattern)
name = '123[ shiv'
new_name = regex.sub('_',name)
gives result(new_name) ::
'_____shiv'
instead of::
'123__shiv'
..thanx in advance
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your regex is creating a range from
whitespace(ASCII Code – 32) toopening bracket - [(ASCII Code – 91) because of that-in between. And that range includes the numbers0 to 9(ASCII Code – 48 to 57).You need to change your regex to: –
Moved
-at the beginning.