Tuesday, February 14, 2006

Matching a Backslash in Java

I've done it a million times in the past but for whatever reason I keep screwing up how to properly write a backslash (\) in a regular expression. I wasted 20+ minutes yesterday trying to figure out why the character class in this
[\";:()\\[\\]<>@.\\,]
regular expression wouldn't match strings containing commas. I'm blogging the solution so I'll have a permanent record and hopefully, I'll once and for all stop screwing it up!

Solution:

[\";:()\\[\\]<>@.\\\\,]

2 comments:

  1. Anonymous10:22 PM

    Your note has been very helpful. Thanks!

    ReplyDelete
  2. Anonymous9:18 AM

    You saved me a huge amount of time there. Thanks!

    /J in Sweden

    ReplyDelete