I'm trying to replace ", " with " and " in a string. I wanna do this with the replaceAll method of String.
Here you can see my try:
String t = "1 hour, 1 minute, 1 second";
System.out.println(t.replaceAll("/(,\s)(?!.*1)/"," and "));
Expected results:
1 hour, 1 minute and 1 second
But I am getting:
1 hour, 1 minute, 1 second
I'm trying to do the replacement with a regular expression. But it's not working. What is wrong with the regex?
question from:
https://stackoverflow.com/questions/65600113/replace-last-coma-and-white-space-with-and 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…