Search code examples
xmlreplacenotepad++

Replace node name XML with regular expresión Notepad++


Edited

I am trying to replace the node name with regular expressions on Notepad++. I hace something similar to this:

<Vehicle_name color="green" type="sub" extra="panoramic roof">
    <InvoiceDateTime InvoiceChargeCents="63" OptionCode="nothing"/>
    <InvoiceDateTime InvoiceChargeCents="63" OptionCode="nothing"/>
    <InvoiceDateTime InvoiceChargeCents="63" OptionCode="nothing"/>
    <InvoiceDateTime InvoiceChargeCents="63" OptionCode="nothing"/>
  </Vehicle>

 <Vehicle_brand color="green" type="sub" extra="panoramic roof">
    <AuthorizationCode InvoiceChargeCents="63" OptionCode="nothing"/>
    <AuthorizationCode InvoiceChargeCents="63" OptionCode="nothing"/>
    <AuthorizationCode InvoiceChargeCents="63" OptionCode="nothing"/>
    <AuthorizationCode InvoiceChargeCents="63" OptionCode="nothing"/>
  </Vehicle>

And I want to get this

<Vehicle_name color="green" type="sub" extra="panoramic roof">
    <InvoiceDateTime InvoiceChargeCents="63" OptionCode="nothing"/>
    <InvoiceDateTime InvoiceChargeCents="63" OptionCode="nothing"/>
    <InvoiceDateTime InvoiceChargeCents="63" OptionCode="nothing"/>
    <InvoiceDateTime InvoiceChargeCents="63" OptionCode="nothing"/>
  </Vehicle_name>

 <Vehicle_brand color="green" type="sub" extra="panoramic roof">
    <AuthorizationCode InvoiceChargeCents="63" OptionCode="nothing"/>
    <AuthorizationCode InvoiceChargeCents="63" OptionCode="nothing"/>
    <AuthorizationCode InvoiceChargeCents="63" OptionCode="nothing"/>
    <AuthorizationCode InvoiceChargeCents="63" OptionCode="nothing"/>
  </Vehicle_brand>

Tnaks


Solution

    • Ctrl+H
    • Find what: <Vehicle(_\w+).+?</Vehicle\K>
    • Replace with: $1>
    • CHECK Match case
    • CHECK Wrap around
    • CHECK Regular expression
    • CHECK . matches newline
    • Replace all

    Explanation:

    <Vehicle            # literally
    (_\w+)              # group 1, 1 or more word character
    .+?                 # 1 or more any character, not greedy
    </Vehicle           # literally
    \K                  # forget all we have seen until this position
    >                   # >
    

    Replacement:

    $1              # content of group 1
    >               # >
    

    Screenshot (before):

    enter image description here

    Screenshot (after):

    enter image description here