0

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. 60885 is an integer. 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. Can anyone suggest how can I achieve this.

Nirav Prajapati
  • 2,987
  • 27
  • 32
yogi_bear
  • 313
  • 4
  • 12

1 Answers1

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

The '.' is a wildcard and must be quoted.

(wildcard = "match any character")

laune
  • 31,114
  • 3
  • 29
  • 42