tss
tss

Reputation: 33

How to replace end of every line that starts with a specific word in Notepad++?

I have a document that looks something like this:

<Objects>
    <Object>
        <Id>1</COLUMN>
        <Type>Type1</COLUMN>
        <Name>Some name</COLUMN>
    </Object>
    <Object>
        <Id>2</COLUMN>
        <Type>Type2</COLUMN>
        <Name>Some name2</COLUMN>
    </Object>
</Objects>

How can I replace all the </COLUMN> in the end of the lines so they match the type shown in the beginning of the lines using Notepad++? I want the result to be something like this:

<Objects>
    <Object>
        <Id>1</Id>
        <Type>Type1</Type>
        <Name>Some name</Name>
    </Object>
    <Object>
        <Id>2</Id>
        <Type>Type2</Type>
        <Name>Some name2</Name>
    </Object>
</Objects>

Upvotes: 0

Views: 86

Answers (2)

karthik manchala
karthik manchala

Reputation: 13640

You can use the following to match:

(<([^>]+)>[^<]+)<\/COLUMN>

And replace with the following:

\1<\/\2>

See RegEX DEMO

Upvotes: 1

splash
splash

Reputation: 13327

Search for: <(\w+)>(.*)</COLUMN> Replace with: <\1>\2</\1>

Upvotes: 1

Related Questions