I am trying to write a java regex to add white space between character and number. I tried few of them but its not working.
For example: This string "FR3456", I would like this to be converted to "FR 3456".
Any help will be appreciated.
I am trying to write a java regex to add white space between character and number. I tried few of them but its not working.
For example: This string "FR3456", I would like this to be converted to "FR 3456".
Any help will be appreciated.
You can add a space between non-digit and digit using Positive Lookbehind & Lookahead
System.out.println("FR3456".replaceAll("(?<=\\D)(?=\\d)"," "));
Here
\D A non-digit: [^0-9]
\d A digit: [0-9]
for more info have a look at Java Regex Pattern
Or use (?<=[^0-9])(?=[0-9])
Here is online demo
Pattern explanation:
(?<= look behind to see if there is:
[^0-9] any character except: '0' to '9'
) end of look-behind
(?= look ahead to see if there is:
[0-9] any character of: '0' to '9'
) end of look-ahead