RegEx that will match the last occurrence of dot in a string

前端 未结 9 1223
梦如初夏
梦如初夏 2020-12-13 16:55

I have a filename that can have multiple dots in it and could end with any extension:

tro.lo.lo.lo.lo.lo.png

I need to use a regex to repla

9条回答
  •  一个人的身影
    2020-12-13 17:34

    To match all characters from the beginning of the string until (and including) the last occurence of a character use:

    ^.*\.(?=[^.]*$)  To match the last occurrence of the "." character
    
    ^.*_(?=[^.]*$)   To match the last occurrence of the "_" character
    

提交回复
热议问题