.net - Regex in C# , Expression in negative lookbehind -
i`m trying write expression mach single code preceded odd number of question marks.
i have found negative look-behind expression match single question mark
pattern (?<!\?)' aaa?'aaa match aaa'aaaa not match aaa??'aaa match --wrong but need detect odd number off question marks not one.
i tried put (?<!\?(??))' did not work. the result want is
aaa?'aaaa match aaa??'aaaa not match aaa???'aaaa match aaa????'aaaa not match aaa?????'aaaa match
the regex looking (?<=(^|[^?])(\?\?)*\?)'.
let's break lookbehind (i changed positive) down:
(^|[^?]) not question mark (possibly start of string, i.e. nothing) (\?\?)* number of question mark pairs \? single question mark so in order quote match, has preceded these tokens in reverse order. should clear forces number of preceding question marks 2n + 1 n >= 0.
Comments
Post a Comment