How to replace space with underscore in an xml file using Notepad++


It is very easy to achieve this using a regex expression. Suppose we have below in an xml file and we want to replace the space inside DisplayName node with underscore.

Sample xml –

<User id="11068577">
	<UserId>11068577</UserId>
	<DisplayName>Dolcese Vita</DisplayName>
	<Address>Texas, US</Address>
</User>
  1. Open Notepad++
  2. Click Ctrl+H to open replace dialog box
  3. Add below in Find What:
(?i)(<DisplayName>.*?)[\s](?=.*</DisplayName>)

4. Add below in Replace with:

\1_\2

5. Result –

<User id="11068577">
	<UserId>11068577</UserId>
	<DisplayName>Dolcese_Vita</DisplayName>
	<Address>Texas, US</Address>
</User>


Interested in Cryptocurrency. Register and start investing here

Earn a side income by affiliate marketing. Learn here how to do it.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: