-1

Please tell me how you can rename replace a tag using Notepad++:

<offer id="124439" name="Alchimia Olive 7,5x30">

Replace by

<offer>Alchimia Olive 7,5x30</offer> <id>124439</id>

The XML file is large if manually, I would like to do with a little blood

2
  • 1
    Are id and name always in same order?
    – Toto
    Commented Apr 27 at 10:16
  • Welcome prokesha! Read The Tour and earn your first badge!
    – MT1
    Commented Apr 27 at 12:12

1 Answer 1

1
  • Ctrl+H
  • Find what: <offer id="(\d+)" name="([^"]+)">
  • Replace with: <offer>$2</offer> <id>$1</id>
  • TICK Match case
  • TICK Wrap around
  • SELECT Regular expression
  • UNTICK . matches newline
  • Replace all

Explanation:

<offer id="     # literally
(\d+)           # group 1, 1 or more digits
" name="        # literally
([^"]+)         # group 2, 1 or more any character that is not a quote
">              # literally

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here


If id and name can be present in any order, use:

  • Find what: <offer(?=.*id="(?<id>\d+)")(?=.*name="(?<name>[^"]+)").+?>
  • Replace with: <offer>$+{name}</offer> <id>$+{id}</id>
2
  • Thanks, it helped!
    – prokesha
    Commented Apr 27 at 14:13
  • 1
    @prokesha: You're welcome, glad it helps. Feel free to mark the answer as accepted, How to accept an answer
    – Toto
    Commented Apr 27 at 14:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .