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
  • 15,303
  • 7
  • 59
  • 83
ha9u63a7
  • 6,233
  • 16
  • 73
  • 108

1 Answers1

0

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

Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125
Jérèm Le Blond
  • 645
  • 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