正则表达式删除文件中最后一个点之后的所有内容 [英] regex to remove everything after the last dot in a file

查看:63
本文介绍了正则表达式删除文件中最后一个点之后的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一个正则表达式来删除文件中最后一个点之后的所有内容.到目前为止,我已经找到了删除第一个点之前的所有文本的方法,但似乎找不到选择文件末尾的方法.你能帮我一下吗?

I'm trying to find a regex for removing everything after the last dot in a file. So far I've found ways to remove all text before the first dot, but I can't seem to find a way to select the end of the file. Could you help me on the way?

提前致谢

推荐答案

您可以尝试以下操作:

\.[^.]*$

匹配包括和最后一个点之后的所有内容.如果您不想包含最后一个点,那么您可以使用正向后视:

to match everything including and after the last dot. If you don't want to include the last dot, then you can use a positive lookbehind:

(?<=\.)[^.]*$

这篇关于正则表达式删除文件中最后一个点之后的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆