How do I replace the whitespace beginning from the last comma in the following string:
foo, bar, 2 3 4 5
should yield:
foo ,bar ,2345
The whitespace up to the second comma should remain intact.
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.
Search for
and replace with nothing. This matches whitespace characters only if there are no commas further ahead in the string.
If you want to implement the rule “all whitespace after the second comma in the string, regardless of whether there are more commas after that”, then you need a regex engine that can handle indefinite repetition inside lookbehind assertions; currently only .NET and JGSoft engines do this. If you’re using one of those, fine:
matches whitespace if it’s preceded by at least two commas.