正则表达式删除所有未跟随数字的句点 [英] regex remove all periods that are not following by digits

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

问题描述

我有 str.replace(/。(?![0-9])/ g,'')

但它删除了除期间和期间后的数字以外的所有内容。

例如3.14变成.1

I have str.replace(/.(?![0-9])/g, '').
But it removes everything except the period and the digit after the period.
For example "3.14" becomes ".1"

我想要的是:

"3.14" -> "3.14"
"hello.world" -> "helloworld"
".hi." -> "hi"
"hi.25" -> "hi.25"

执行此操作的正则表达式是什么?

What is the regex for doing this?

推荐答案

如果你没有逃避点,则意味着匹配任何角色。

If you don't escape the dot it means "match any character."

str.replace(/\.(?![0-9])/g, '')

这篇关于正则表达式删除所有未跟随数字的句点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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