Search code examples
notepad++sublimetext3nsregularexpression

How can I use regular expressions to find a word and copy it to a specific location?


Can you please tell me how I can use regular expressions to find what is written between the tags, copy it and paste it between the tags? I've been racking my brains for an hour, I can't find the formula))

Example:

<category id="1"><name>Мужские куртки</name><short></short></category>
<category id="2"><name>Мужские брюки</name><short></short></category>
<category id="3"><name>Мужские портянки</name><short></short></category>

Need to:

<category id="1"><name>Мужские куртки</name><short>Мужские куртки</short></category>
<category id="2"><name>Мужские брюки</name><short>Мужские брюки</short></category>
<category id="3"><name>Мужские портянки</name><short>Мужские портянки</short></category>

Solution

  • You may try the following find and replace, in regex mode:

    Find:    <category id="(\d+)"><name>(.*?)</name><short></short></category>
    Replace: <category id="$1"><name>$2</name><short>$2</short></category>
    

    Demo