Multi-line regular expressions in Visual Studio

后端 未结 7 882
庸人自扰
庸人自扰 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:44

    This works today in Visual Studio 2012:

    fooPatternToStart.*(.*\n)+?.*barPatternToEnd
    

    See how the (.*\n)+? part does the match across multiple lines, non-greedy.
    fooPatternToStart is some regex pattern on your start line, while barPatternToEnd is your pattern to find on another line below, possibly many lines below...

    Example found here.

    Simple and effective :)

    Note: before VS2012, the pattern that worked was: fooPatternToStart.(.\n)+@.*barPatternToEnd

提交回复
热议问题