Remove last occurrence of character

前端 未结 4 1419
醉梦人生
醉梦人生 2021-02-07 11:58

A question came across talkstats.com today in which the poster wanted to remove the last period of a string using regex (not strsplit). I made an attempt to do thi

4条回答
  •  时光取名叫无心
    2021-02-07 12:07

    I'm pretty lazy with my regex, but this works:

    gsub("(*)(.)([0-9]+$)","\\1\\3",N)
    

    I tend to take the opposite approach from the standard. Instead of replacing the '.' with a zero-length string, I just parse the two pieces that are on either side.

提交回复
热议问题