Search code examples
notepad++

It is about Notepad++ regular expression replacement


I want to replace

<th scope="col">@translate(Product)</th> 

code row to

<th scope="col">{{trans("file.Product")}}</th> 

in NotePad++ but I can't write exactly correct regular expression. Help me please.


Solution

    • Ctrl+H
    • Find what: <th scope="col">\K@translate\((.+?)\)(?=</th>)
    • Replace with: {{trans("file.$1")}}
    • CHECK Match case
    • CHECK Wrap around
    • CHECK Regular expression
    • Replace all

    Explanation:

    <th scope="col">        # literally
    \K                      # forget all we have seen until this position
    @translate              # literally
    \(                      # openning parenthesis
    (.+?)                   # group 1, 1 or more any character, not greedy
    \)                      # closing parenthesis
    (?=</th>)               # positive lookahead, make sure we have a closing tag after
    

    Screenshot (before):

    enter image description here

    Screenshot (after):

    enter image description here