I want to write a regex to substitute remove white spaces within my string as follows:
String : user1: group user2 :group2 user3 : group3
to
user1:group user2:group2 user3:group3
What I tried so far is:
$argument =~ s/\s+\:/\:/g;
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.
You are nearly there:
There is no need to escape the
:, and you want to search for whitespace both before and after the colon. Instead of\s+which searches for one or more, I used\s*which searches for zero or more. That way you will match if there are no spaces before but some after, or vice-versa.