正则表达式除最后一个字符外的所有字符 [英] Regular Expression all characters except last one

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

问题描述

这是我的字符串:50.00.00..00.00

我想匹配除最后一个之外的所有 .,所以在替换后我最终得到 50000000.00

I want to match all . except the last one, so after a replace I end up with 50000000.00

有人可以帮我解决这个问题吗?

Can somebody help me with this?

推荐答案

\.(?=.*\.)

匹配一个点(\.),它后面必须有另一个点((?=.*\.)).

Matches a dot (\.), which there must be another dot following it ((?=.*\.)).

(假设正则表达式引擎支持 lookahead,例如 PCRE、Python 等.)

(This assumes the regex engine supports lookahead, e.g. PCRE, Python, etc.)

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

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