Friday, April 25, 2008

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. Sometimes i spent a little time to solve it but the problems is i simply forget it at next times. It is wasting times 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:
[\";:()\\[\\]<>@.\\\\,]

notes: character '/' is treat as normal string "/", and character '\' as character '\\'

No comments:

Man Utd's next generation of wonderkids

Manchester United have set off on their pre-season United States tour with a number of young stars involved, but some other talents have lef...