简体   繁体   English

在Java中使用点号分隔的字符串进行模式匹配

[英]Pattern matching with Strings seperated by dots in Java

I need to find strings that match a particular pattern. 我需要找到匹配特定模式的字符串。 For example in the following condition: 例如,在以下情况下:

if("1.6.1.1.60885.5".matches("1.6.1.1.n.5".replaceAll("n", "\\\\d{0,10}")))

then it should be true, since n can be any integer. 那么它应该为真,因为n可以是任何整数。 60885 is an integer. 60885是一个整数。 This works fine. 这很好。

if("1.6.1.1.60885".matches("1.6.1.1.n.5".replaceAll("n", "\\\\d{0,10}")))

then it should be false. 那么应该是错误的。 But I get this also as true. 但是我也这样认为。

I just need the n to be any integer but the dots position has to be considered. 我只需要n为任何整数,但必须考虑点的位置。 Can anyone suggest how can I achieve this. 谁能建议我如何实现这一目标。

matches("1\\.6\\.1\\.1\\.n\\.5",... )

The '.' “。” is a wildcard and must be quoted. 是通配符,必须加引号。

(wildcard = "match any character") (通配符=“匹配任何字符”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM