正则表达式-匹配第二个点

时间:2019-03-18 21:53:05

标签: java regex

我有一些数字,它们之间用一个点或一个点分隔,例如:

1341.1241,
2.4, 
552 or
1

如果出现第二个点,当满足以下条件之一时,我希望它与正则表达式匹配:

.2341.1525 (if the dot is the first character [.]2341.1525)

.53453 (also when theres a single dot as the first char in general [.]53453

1235.446.634 (as the second dot in the string 1235.446[.]634)

51524.24. (its also possible that the dot appears as the last character 51524.24[.])

然后将删除匹配的点。我正在使用Java。

是否甚至可能有一个包含这些条件的正则表达式?如果是这样,如果有人完全分享我的想法,我会很高兴。

预先感谢

1 个答案:

答案 0 :(得分:0)

看起来{}完成了任务。括号用于组捕获,可让您通过合并捕获来删除点。

示例代码:

(\\d*\\.\\d*)\\.(\\d*)
相关问题