Multiline regular expression search in Visual Studio Code

前端 未结 5 1075
栀梦
栀梦 2020-12-05 09:43

Multiline regular expression search doesn\'t work in VS Code version 1.27.2 .

Theoretically aaa(\\n|.)*bbb should find string starting from aaa and endi

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-05 10:06

    You can find and replace in multiple lines by using this simple regex : StringStart\r\nStringEnd

    For example

    public string MethodA(int x)
    { 
        var user;  
    }
    
    public string MethodB(string y)
    {
        var user;  
    }
    
    public string MethodC(int x)
    { 
         var user;  
    }
    
    public string MethodD(float x)
    { 
         var user;  
    }
    

    If you want to replace the name of user variable with customer along with method parameter name to user but only for the int ones.

    Then the regex to find will be : int x)\r\nEnterBlankSpacesHereToReachTheString{\r\nEnterBlankSpacesHereToReachTheStringvar user

    and regex to replace will be : int user)\r\nEnterBlankSpacesHereToReachTheString{\r\nEnterBlankSpacesHereToReachTheStringvar customer

    See for reference

提交回复
热议问题