rmtogether
asked on
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
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
ASKER
hi, markoillic
I think there is an error in the following 2 parts
"([a-z]+)(\d{1,2})" and "$1\s$2
I think there is an error in the following 2 parts
"([a-z]+)(\d{1,2})" and "$1\s$2
Regex.Replace(your_string, @"([a-zA-Z])(\d)", @"\1 \2");
ASKER
Hi, kaufmed:
I try this string "June4July13". looks like not right..
can I add spaces to convert it to "June 4 July 13"?
Thanks
I try this string "June4July13". looks like not right..
can I add spaces to convert it to "June 4 July 13"?
Thanks
Sorry, I missed the second requirement:
Regex.Replace(your_string, @"([a-zA_Z])(\d)|(\d)([a-z A-Z])", @"\1 \2");
Regex.Replace(your_string,
ASKER
Hi, kaufmed:
sorry I try your code above, but the result is "Jun\\1 \\2Jul\\1 \\23" not "June 4 July 13"
sorry I try your code above, but the result is "Jun\\1 \\2Jul\\1 \\23" not "June 4 July 13"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
By "call the function twice" I mean call Regex.Replace() twice.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@Pui_Yun
Nice :)
Nice :)
ASKER
Thank you so much
string s = Regex.Replace(soureString ,"([a-z]+)(\d{1,2})", "$1\s$2")