Search code examples
c#visual-studionotepad++multilinefind-replace

Multi line Find and Replace get set property notepad++ or visual studio


I have to replace expression below:-

public string Body =>
        this._body;

To:

public string Body
      {
        get{return _body;} 
          set{_body = value;}
    }

I am using Notepad++ to find and replace as below:- Find regx: =>\s*.*?; Replace regx: {get{return\s*.*?;} set{\s*.*? = value;}}

which seems not working and replace it incorrectly without property name as below:-

Public string Body {get{returns*.*?;} set{s*.*? = value;}}

How can we change the expression to get the desired result with property name? Also can we do something like this in Visual Studio? Thank you.


Solution

  • Here is a way to do the job with Npp:

    • Ctrl+H
    • Find what: \b(public\s+string\s+Body)\s+=>\s+this\.(\w+);
    • Replace with: $1 {get{returns $2;} set{$2 = value;}}
    • Replace all