Multi-line regular expressions in Visual Studio

后端 未结 7 884
庸人自扰
庸人自扰 2021-01-30 09:58

Is there any way to get Visual Studio to perform a regex replace across multiple lines (let the match cross line boundaries)? I know there are many editors I can use for this, b

7条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-30 10:36

    Note: this answer is using the regex syntax used in Visual Studio up to and including VS 2012. In VS 2013 and later, the regex syntax has changed.

    You can include \n in the expression. As an example, here is a regex that I use to "clean" auto-generated SQL scripts from anything that is not a stored procedure (it will match text blocks that start with a line containing "Object: " followed by something that is not "StoredProcedure", then matching the following lines up to a line consists of the word "GO"):

    /\*+ Object\::b:b~(StoredProcedure)(.*\n)#GO\n
    

提交回复
热议问题