Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a string which contains data in the following format:

<employee:First Name>xyz</employee:First Name> <employee:Last Name>abc</employee:Last Name>

I want to remove spaces between two tags and not in the data enclosed within a tag
i.e

<employee:First Name>xyz</employee:First Name><employee:Last Name>abc</employee:Last Name>

So the space between </employee:First Name> and <employee:Last Name> is removed.

I want to do this with a regular expression. Please help

What I have tried:

Regex.Replace(string,(.*)>\s<(.*),(.*)><(.*))
Posted
Updated 17-Jun-17 22:17pm

Try:
Regex.Replace(input, @">\s*<", "><", RegexOptions.Multiline)
/ravi
 
Share this answer
 
You should try something like:
C#
Regex.Replace(string,(.*)>\s<(.*),$1><$2)

But this code is not C# and the RegEx is over complicated.

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900