I have an example input that can be of any length and want to add a space every 4 characters.
for example input = xxxxxxxxxxxx
result I expect: xxxx xxxx xxxx
I have looked at the replaceAll() method but wondering how I can create a match that returns me the 4th, 8th, 12th etc character index so I can do something like this:
input.replaceAll("([\\S\\s)]{4})\\G", " " + input.charAt(index - 1))
where index somehow gets modified to get the appropriate index in which the regular expression of mine has found the 4th character.