c# - Exclude starts with but include ends with -
i can't figure out myself, have match string starts asp. , ends _aspx, need exclude start of match (the asp. part).
for example,
string input = "random stack trace text asp.filename_aspx random text"; regex r = new regex("regular expression needed!!!"); var mc = r.matches(s); foreach (var item in mc) { console.writeline(item.tostring()); } and have needs output this,
filename_aspx
that's job positive lookbehind assertion:
regex r = new regex(@"(?<=\basp\.)\s+_aspx"); (?<=\basp\.) ensures asp. present before starting position of match, doesn't include in match result. \b word boundary anchor asserts don't match wasp, asp.
\s+ matches 1 or more non-whitespace characters (this assumes filenames don't contain spaces).
Comments
Post a Comment