How to replace all content from XML tag with blank in notepad++?



  • I would like to remove all content from id="*" within a tag and replace with blank. There are 100s of different id values and I would like to remove all of it.

    <Type>Computer</Type>
    <deductible id=“d6349782384236423784ABD#1212” >
    <Type>Standard</Type>
    </deductible>
    <limit id=“1123123VHGHJKJH65776BJHBHG9”>
    <Type>Aggregate</Type>
    <ivalue>10000</ivalue>

    I want output like this:

    <Type>Computer</Type>
    <deductible>
    <Type>Standard</Type>
    </deductible>
    <limit>
    <Type>Aggregate</Type>
    <ivalue>10000</ivalue>



  • Hi @rajat-narang, All:

    -Try this:

    Open the Replace dialog (Ctrl + H) and type in:

    Search: (?-s)\x20id="[^"]+"\x20?
    Replace: [leave empty]
    

    or (if curly quotes are used)

    Search: (?-s)\x20id=“[^”]+”\x20?
    Replace: [leave empty]
    

    Check the Wrap around option
    Select the Regular expression search mode
    Click on the `Replace All´´ button

    Hope this helps.



  • @astrosofista said in How to replace all content from XML tag with blank in notepad++?:

    (?-s)\x20id=“[^”]+”\x20?

    Thank you so much ! It worked perfectly



  • @rajat-narang said in How to replace all content from XML tag with blank in notepad++?:

    Thank you so much ! It worked perfectly

    Glad it helped you.

    BTW, I forgot to remove the (?-s) modifier, as the * is not used in the expression. It does no harm, but it’s useless.



  • @astrosofista ,

    BTW, I forgot to remove the (?-s) modifier, as the * is not used in the expression. It does no harm, but it’s useless.

    Nitpick: it’s the . operator that is affected by (?-s), not the *, since the s flag is “dot matches newline”. But . wasn’t used in your expression, either, so the flag-clearing is still useless. :-)

    Well, not completely useless. As we help people in the forums, always including either (?-s) or (?s) will ensure we never have to care what the status of their checkbox is, so having one of the two in our default answer-regex is a good idea. ;-)



  • @PeterJones said in How to replace all content from XML tag with blank in notepad++?:

    Nitpick: it’s the . operator that is affected by (?-s), not the *, since the s flag is “dot matches newline”. But . wasn’t used in your expression, either, so the flag-clearing is still useless. :-)

    Yep, my bad, I stated a wrong reason, thank you for notice it :)

    Well, not completely useless. As we help people in the forums, always including either (?-s) or (?s) will ensure we never have to care what the status of their checkbox is, so having one of the two in our default answer-regex is a good idea. ;-)

    Agree, learned that in this forum, so the (?-s) modifier is my default setup.

    Cheers


Log in to reply