- if you want to make
.*
to be non-greedy you need to add?
right after*
. replaceAll
will replace all occurrences of matching parts, so you should probably usereplaceFirst
try
System.out.println("city,state,country".replaceFirst(".*?,", ""));
output:
state,country
If you can't use replaceFirst
and need to stay with replaceAll
then @Reimeus answer is probably what you are looking for.