Java regular expression: how to include '-'

Posted by changed on Stack Overflow See other posts from Stack Overflow or by changed
Published on 2010-04-02T20:33:07Z Indexed on 2010/04/02 20:43 UTC
Read the original article Hit count: 200

Filed under:
|

I am using this pattern and matching a string.

String s = "//name:value /name:value";
if (s.matches("(//?\\s*\\w+:\\w+\\s*)+")) {
  // it fits
}

This works properly.
But if I want to have a string like "/name-or-address:value/name-or-address:value" which has this '-' in second part, it doesn't work.
I am using \w to match A-Za-z_, but how can I include - in that?

© Stack Overflow or respective owner

Related posts about java

Related posts about regex