0

I was trying the pattern ^\\+[0-9]+ to match +852(2)78911, but it seems that

Pattern.matches("^\\+[0-9]+", s)

is returning false. When I tried it in regexr it is working fine i.e. giving me a match. Am I not escaping this correctly in Java sense?

jaco0646
  • 13,332
  • 7
  • 54
  • 75
ha9u63ar
  • 5,455
  • 9
  • 62
  • 92

1 Answers1

0

Try this regex instead: ^\\+[0-9\\(\\)]+$

Casimir et Hippolyte
  • 85,718
  • 5
  • 90
  • 121
Jérèm Le Blond
  • 625
  • 5
  • 23
  • 1
    You can find the formatting features here: http://stackoverflow.com/editing-help . There's no need to escape parenthesis inside a character class. Note too that when you use the `matches` method, anchors are implicit. – Casimir et Hippolyte Jul 28 '16 at 11:16