In Java I want to insert a space after a string but only if the string contains "MAVERICK". I think using replaceAll() method which uses regular expressions as a parameter will do it, but i am not really getting it.
Here is what i have
String s = "MAVERICKA";
//the last character can be from the following set [A,Z,T,SE,EX]
So, i want the function to return me the string "MAVERICK A" or "MAVERICK EX". Ex.
Also, if the string is already in the correct format it should not insert a space. i.e
How about something like
s = s.replaceAll("MAVERICK(A|Z|T|SE|EX)", "MAVERICK $1");
Another solution without knowing the trailing letters would be:
String spaced_out = s.replaceAll("(MAVERICK)(?!\s|$)", "$1 ");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With