c# - Why does this Regular Expression match nothing? -
i want replace instances of consecutive non-lowercase-alphabet-letters single space each instance. works, why inject spaces in between alphabet letters?
const string pattern = @"[^a-z]*"; const string replacement = @" "; var reg = new regex(pattern); string = "the --fat- cat"; string b = reg.replace(a, replacement); // b = " t h e f t c t " should "the fat cat"
because of *
(which repeats previous token zero or more times). must finds match in boundaries since empty string exists in boundaries.
const string pattern = @"[^a-z]+";
Comments
Post a Comment