Can regex match be based on two lines of text?

后端 未结 2 1306
逝去的感伤
逝去的感伤 2021-01-19 00:32

Let\'s say I have

def
abc
xyz
abc

And I want to match

xyz
abc

<
相关标签:
2条回答
  • 2021-01-19 01:06

    Many regex implementations allow explicit line terminators. If \n is the line separator, then just search for xyz\nabc.

    0 讨论(0)
  • 2021-01-19 01:13

    Regexes work on whatever text you give them, multiline or otherwise. If it happens to contain linefeeds, then it's nominally "multiline" text, but you don't have to do anything special to match it with regexes. Linefeed is just another character.

    The name "multiline flag" (or "multiline mode") confuses many people. All that flag does is change the meaning of the ^ and $ anchors, allowing them to match at the beginning and end of logical lines as well as the beginning and end of the whole text.

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