Regex to match digit to letter transition so i can put space between them
Is there a way to build a rege开发者_C百科x to match a digit to letter transition for e.g.:
e2, s5, c8
I have a .net application that opens a file content into a richtextbox, I want this application to find a transition from digit to letter and separate letter and digit with a white space.
Try this:
string resultString = null;
try {
resultString = Regex.Replace(subjectString, @"(\d{1})([:alpha:]{1})", "$1 $2", RegexOptions.IgnoreCase);
} catch (ArgumentException ex) {
// Syntax error in the regular expression
}
MATCH ANY:
e2, s5, c8
REGEX:
([a-z]) (\d) ,
OR:
([a-z])(\d),
Group1 is letters, group2 is numbers, rebuild string with group1 + " " + group2, to give: e 2 , s 5, c 8
Test here: http://gskinner.com/RegExr/
精彩评论