Regular expression to match a block of text up to the first double new line?

前端 未结 5 655
面向向阳花
面向向阳花 2020-12-11 20:41

I\'m making a simple Textile parser and am trying to write a regular expression for \"blockquote\" but am having difficulty matching multiple new lines. Example:

         


        
5条回答
  •  半阙折子戏
    2020-12-11 20:44

    Edit: Ehr, misread the question.. "bq." was significant.

    echo preg_replace('/^bq\.(.+?)\n\n/s', '
    $1
    ', $str, 1);

    Sometimes data that is entered via webforms contains \r\n instead of just \n which would make it

    echo preg_replace('/^bq\.(.+?)\r\n\r\n/s', '
    $1
    ', $str, 1);

    The questionmark makes it add the closing blockquotes after the first double return found ("non-greedy" I believe it's called), so any other double returns are left alone (if that is not what you want, take it out obviously).

提交回复
热议问题