Regex match entire words only

后端 未结 7 1309
挽巷
挽巷 2020-11-21 05:35

I have a regex expression that I\'m using to find all the words in a given block of content, case insensitive, that are contained in a glossary stored in a database. Here\'s

7条回答
  •  独厮守ぢ
    2020-11-21 06:20

    If you are doing it in Notepad++

    [\w]+ 
    

    Would give you the entire word, and you can add parenthesis to get it as a group. Example: conv1 = Conv2D(64, (3, 3), activation=LeakyReLU(alpha=a), padding='valid', kernel_initializer='he_normal')(inputs). I would like to move LeakyReLU into its own line as a comment, and replace the current activation. In notepad++ this can be done using the follow find command:

    ([\w]+)( = .+)(LeakyReLU.alpha=a.)(.+)
    

    and the replace command becomes:

    \1\2'relu'\4 \n    # \1 = LeakyReLU\(alpha=a\)\(\1\)
    

    The spaces is to keep the right formatting in my code. :)

提交回复
热议问题