22 November 2010

Regex in Java

If you want to use regex in Java, keep in mind one note. The backslash is a skip character in regex. In Java you need to have two backslashes to define one. For example \” in regex means a “ character. While, in java you should be using \\”. Two backslashes will translate into one in Java and then translate as a skip character for regex. It gets even trickier when you want to use a backslash in your regex. You need to have four backslashes such as \\\\. They are going to be translated into \\ for the regex and then the regex will distinguish a backslash if it exists within the string you are parsing (since \\ is the backslash annotation for regex.)

If you need a really complete and useful source for regular expression, you can always trust oreilly publishing.


Resources:

No comments:

Post a Comment