Question : C#  regular expression question (replace)

Hi, Experts

I would like to add a "space" between number and character for a given string

for example:

March3--> add a "space" between "h" and "3" --> becomes March 3
June 2July 5 --> add a "space" between "2" and "J"--> becomes June 2 July 5

Is it possible? how can I do it. Thanks in advance

Answer : C#  regular expression question (replace)

So apparently I'm tired...


Disregard the above. Here is a tested version. The only caveat is that you will have to call the function twice for something like "June4July13" because the regex will find "e4"and "y1" and not find "4J" on the first pass. You have to execute it a second rime to pick up the "4J".


    Regex.Replace(your_string, @"[a-zA-Z]\d|\d[a-zA-Z]", AlterMatch);

    \\ AlterMatch function
    string AlterMatch(Match m)
    {
        return string.Concat(m.Value[0], " ", m.Value[1]);
    }
Random Solutions  
 
programming4us programming4us