What’s the C# equivalent of this JavaScript Regular Expression?
str.replace(/(\w)\w*/g, "$1");
Javascript Input + Result (Desired):
Input: I like pie!
Result: i l p!
C# Input + Result (Using Tim’s Version posted below):
Input: I like pie!
Result: \1 \1 \1!
Any other ideas?
This change is necessary because
\wmatches a lot more in .NET regexes than in JavaScript regexes.(Unless you also want to match words that contain non-ASCII letters/digits, in which case `@”(\w)\w*” would be better.)