Regular expression search replace in Sublime Text 2

前端 未结 6 1530
鱼传尺愫
鱼传尺愫 2020-11-27 09:10

I\'m looking to do search replace with regular expressions in Sublime Text 2. The documentation on this is rather anemic. Specifically, I want to do a replace on groups, so

6条回答
  •  星月不相逢
    2020-11-27 09:42

    Usually a back-reference is either $1 or \1 (backslash one) for the first capture group (the first match of a pattern in parentheses), and indeed Sublime supports both syntaxes. So try:

    my name used to be \1
    

    or

    my name used to be $1
    

    Also note that your original capture pattern:

    my name is (\w)+
    

    is incorrect and will only capture the final letter of the name rather than the whole name. You should use the following pattern to capture all of the letters of the name:

    my name is (\w+)
    

提交回复
热议问题