Zoe
Zoe

Reputation: 51

Wildcard string in notepad++ to replace date format

I am struggling to figure out how to replace date format in notepad++ I have a key which contain different dates.

<pk2>2014/01/03</pk2>

Should be changed to:

<pk2>2014-01-03</pk2> 

and so on.

Any suggestion on how to do this?

Upvotes: 2

Views: 507

Answers (1)

Toto
Toto

Reputation: 91508

This will replace / with - only inside tag <pk2>...</pk2>.

Tell me if you want to replace other dates.


  • Ctrl+H
  • Find what: (?:<pk2>|\G(?!^))\d+\K/(?=.*</pk2)
  • Replace with: -
  • CHECK Match case
  • CHECK Wrap around
  • CHECK Regular expression
  • UNCHECK . matches newline
  • Replace all

Explanation:

(?:             # non capture group
    <pk2>           # opening tag pk2
  |               # OR
    \G(?!^)         # restart from last match position if not beginning of line
)               # end group
\d+             # 1 or more digits
\K              # forget all we have seen until this position
/               # a slash
(?=             # positive lookahead, make sure we have after:
    .*              # 0 or more any character but newline
    </pk2           # closing tag
)               # end lookahead

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

Upvotes: 2

Related Questions