I am not familiar with regular expression.
For a string, I want to replace all the non-letter and non-digit characters with space, and then merge the spaces so that there is no two consecutive spaces.
How to achieve that using regular expression?
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.
Use two replacements:
[^a-zA-Z0-9]by a space[ ]{2,}by a single space (the character class is only needed here because SO’s parser messes up – usually a space suffices on its own)In PowerShell that’d look like