c# - Negative lookahead of an odd number `\` before the requested letter -


how can 1 find letters a of string condition there no odd number of \ directly in front of it.

to 1 \ be

@"(?<!\\)a" 

which works quiet well. how odd numbers of \ excluded?

for instance

  • a, \\a, \\\\a, ... should allowed
  • \a, \\\a, \\\\\a, ... should neglected

ps. nice if c# class system.text.regularexpressions.regex handle result.

you can use following:

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

see demo

explanation:

  • (?<!\\) lookbehind no \ (to avoid matching \'s between)
  • (?:\\\\)* match 0 or more of double slashes \\ (escaped \ each..) match number of \'s
  • a match literal a

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -