假设我有这段文字:
Saturday and Sunday and Monday and Tuesday and Wednesday and Thursday and Friday are days of the week.
我希望除了最后一个
and
以外,其他的都用逗号替换:Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday and Friday are days of the week.
有没有一种简单的正则表达式方法可以实现这个?据我所知,正则表达式中的replace
方法会替换整个字符串。