Negative look of the odd number `\` before the requested letter

How to find all the letters of a astring, but with the condition that there is no odd number in front of it \.

For one there \will be

@"(?<!\\)a"

which works quietly. But how to exclude all odd numbers \?

for instance

  • a, \\a, \\\\a, ... it should be allowed
  • \a, \\\a, \\\\\a, ... be ignored

PS. It would be nice if the C # class System.Text.RegularExpressions.Regexcould handle your result.

+4
source share
1 answer

You can use the following:

(?<!\\)(?:\\\\)*a

See DEMO

Explanation:

  • (?<!\\)lookbehind for no \(to avoid a match \between)
  • (?:\\\\)* \\ ( \ each..), \ 's
  • a match literal a
+3

All Articles