tags:

views:

43

answers:

1

Difference between Java & .Net Framework Regular Expressions Pattern

I am trying to convert My .Net Framework but patterns are not valid

Can any one point out the major differences in regex patterns

e.g. How would we name the grouping constructs in java, etc.

+2  A: 

There are many differences that are summarised here.

The most important ones are:

  1. In Java strings, you need to escape all the backslashes (@"\s" becomes "\\s")
  2. Java does not support named capturing groups
  3. Java does not support infinite repetition inside lookbehinds.
  4. Java does not support conditionals ((?(?=regex)then|else))
  5. Unicode properties are named differently.

Most other differences are minor. One difference that is not mentioned above is Java's lack of support for balanced (recursive) regexes which I hope you don't have to use, ever.

If you need to convert lots of complicated regexes, consider investing in RegexBuddy which will do that for you.

Tim Pietzcker
Thanks Tim for you reply and pointing to a really useful resource.
regexhacks