Home > other >  How can I replace this text with regex in Notepad ?
How can I replace this text with regex in Notepad ?

Time:01-09

In my file I have a lot of:

<WYYYYMMDD>
</WYYYYMMDD>

I want to find / replace them:

<Meeting Week=“WYYYYMMDD”>
</Meeting>

YYYYMMDD are dates, like 20220108.

Can I do this with Find Replace in Notepad ?

Example:

<W20220805>
</W20220805>

W never changes.

CodePudding user response:

  • Ctrl H
  • Find what: <(W\d{8})>(\R)</\1>
  • Replace with: <Meeting Week="$1">$2</Meeting>
  • CHECK Match case
  • CHECK Wrap around
  • CHECK Regular expression
  • Replace all

Explanation:

<               # literally <
(W\d{8})        # group 1, W && 8 digits
>               # literally >
(\R)            # group 2, any kind of linebreak
</\1>           # </  & backreference to group 1 & >

Replacement:

<Meeting Week="$1"> # new tag with week value = content of group 1
$2                  # same linebreak
</Meeting>          # end tag

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

  •  Tags:  
  • Related