Regex to match only the first line?

前端 未结 4 1204
自闭症患者
自闭症患者 2021-02-01 17:32

Is it possible to make a regex match only the first line of a text? So if I have the text:

This is the first line.
This is the second line. ...

It would matc

4条回答
  •  野的像风
    2021-02-01 18:13

    There is also negative lookbehind function (PowerGREP or Perl flavor). It works perfectly for my purposes. Regex:

    (?

    where

    • (? is negative lookbehind - regex matches only strings that are not preceded by a whitespace(s) (\s also stands for a line break)
    • ^ is start of a string
    • (.+) is a string
    • $ is end of string

提交回复
热议问题