Search code examples
notepad++

Notepad++ - find and move lines


I have a big language file that has a lot of block like the following:

<trans-unit id="common:CommandDescription_EditTest:Manager.CommandDescription.Text">
        <source>Редактировать тест</source><target>Editar prueba</target>
        <alt-trans>
          <target xml:lang="en" state="translated">Edit test</target>
          <target xml:lang="pt" state="x-autotrans">Editar teste</target>
          <target xml:lang="fr" state="translated">Editer test</target>
          <target xml:lang="zh" state="translated">编辑检查</target>
          <target xml:lang="es" state="translated">Editar test</target>
          <target xml:lang="it" state="translated">Modificare test</target>
        </alt-trans>`

I need <target>Editar prueba</target> to go between <alt-trans> tags taking into account that there are a lot of these blocks.

How can I achive that?


Solution

    • Ctrl+H
    • Find what: (<target>.+?</target>)(\s+)(<alt-trans>)(\s+)
    • Replace with: $2$3$4$1$4
    • CHECK Match case
    • CHECK Wrap around
    • CHECK Regular expression
    • Replace all

    Explanation:

    (                   # group 1
        <target>            # openning tag
        .+?                 # 1 or more any character, not greedy
        </target>           # closing tag
    )                   # end group
    (\s+)               # group 2, 1 or more spaces character, including linebreak
    (<alt-trans>)       # group 3, openning tag
    (\s+)               # group 4, 1 or more spaces character, including linebreak
    

    Replacement:

    $2      # content of group 2, spaces for indentation
    $3      # content of group 3, openning tag <alt-trans>
    $4      # content of group 4, spaces for indentation
    $1      # content of group 1, the target tag
    $4      # content of group 4, spaces for indentation
    

    Screenshot (before):

    enter image description here

    Screenshot (after):

    enter image description here