Multi-line regular expressions in Visual Studio

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

    Use the replace in files dialog Ctrl-Shift-H and the single line option (?s):

    (?s)start.*end
    

    finds

    start
    two
    three
    end
    

    Singleline means: each file is treated as single line, dot . matches newline \n. Downside: you must use Find All and replace all, or replace by hand. Find next does not work.

    For the non-modal dialog Ctrl-H and find next, use (.*\n)* to match any number of lines:

    start(.*\n)*.*end
    

    Either way, you can replace your findings with multiple lines by inserting \n.

    0 讨论(0)
提交回复
热议问题