c# - Get un-prefixed/un-escaped text with RegEx -


i have following input text:

a b c d e \f g h jkl \m 

and mach characters without \ prexix, each of characters individually. basically, match, i'd a, b, c, d, e, g, h, i, j, k , l, f , m not passing because prefixed/escaped.

i got far

([^\\]([a-z]{1})) 

which works not expected: - a ignored, because there nothing before (and testing backslash) - each letter matched space before - jkl matches j space before, , kl 1 string.

i have tried different other variations parantheses not successful that.

the negated character class [^\\] consuming pattern matches text, adds match value , advances regex index end of match.

use non-consuming negative lookbehind:

(?<!\\)[a-z] ^^^^^^^ 

see regex demo. being non-consuming pattern, (?<!\\) checks if there backslash before ascii uppercase letter, , if there any, engine fails match. if there \, letter matched (while backslash remains missing in match value).

c# code:

var results = regex.matches(s, @"(?<!\\)[a-z]")         .cast<match>()         .select(m => m.value)         .tolist(); 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -