Home > OS >  VS Code Regex Search and Replace - whitespace removal between global search of two objects (if and r
VS Code Regex Search and Replace - whitespace removal between global search of two objects (if and r

Time:06-14

1 of the 2000 resultsI would like to remove the line in between this filtered search: Here is the regex that I have in my Search in VS Code - ^(?![ \t]*//).*^.*\bif\b.*$\n\n(?![ \t]*//).*^.*\breturn\b.*$

I would like to get rid of the line in between the if and the return but keep the code, just remove the line in between. I know I can keep the result with the $0 but cant figure out the next part, any help would be much appreciated! Search Box

Here is an example of what I want in the results:

if o.R == nil {
   
   return nil
}

Here are some examples of what I do not want in the results:

if err != nil {
        return err
    }

Also unwanted in the results:

if foreign.R == nil {
        foreign.R = &portfolioBinOperationR{}
        return nil
    }

Here is the my VSCode after trying your solution...where am I going wrong? After trying solution

CodePudding user response:

Search by (if.*?\{)([\s\n]{2,}?)(?=^.*?return) and replace with $1\n. See the regex enter image description here

After Replacement

enter image description here

  • Related