I want to replace the spaces surrounded by digits or numbers by -.
so if my string is I am Bob 12 12 This should get transformed to I am Bob 12-12.
Please suggest some possible answers using Java.
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.
This looks for a space (
\\s) preceded by a digit ((?<=\\d)) and followed by a digit ((?=\\d)), and replaces that space with a dash.If you want to replace groups of consecutive spaces, change
\\sto\\s+.