How to replace last dot in a string using a regular expression?

后端 未结 4 1177
小蘑菇
小蘑菇 2021-01-05 09:25

I\'m trying to replace the last dot in a String using a regular expression.

Let\'s say I have the following String:

String string = \"hello.world.how         


        
4条回答
  •  时光取名叫无心
    2021-01-05 10:07

    The regex you need is \\.(?=[^.]*$). the ?= is a lookahead assertion

    "hello.world.how.are.you!".replace("\\.(?=[^.]*$)", "!")
    

提交回复
热议问题