1

Can you help me to understand / convert follwoing .net regex into java

@"(?<!\\)(?'M'[^|%])" ?
Daniel Hilgarth
  • 166,158
  • 40
  • 312
  • 426
Rajender Saini
  • 576
  • 2
  • 9
  • 23

1 Answers1

1

This regex consists of two groups.

The first one (?<!\\) is a lookbehind assertion. It will match only if the previous letter is not a backslash. The second one (?'M'[^|%]) is a named capturing group (called M), that matches any character except "|" and "%".

I.e. the regex will match "a", and not match "\a" or "%".

Java does not support the named capture, but

(?<!\\)([^|%])

should work fine for you. You'd reference the first group by number, instead of by name then.

Note that you may have to escape backslashes leading to (?<!\\\\) for the first part.

Jens
  • 24,655
  • 6
  • 74
  • 116