php - Where did I go wrong in my regex lookaround? -
i'm trying pull first paragraph out of markdown formatted documents:
this first paragraph.
this second paragraph.
the answer here gives me solution matches first string ending in double line break.
perfect, except of texts begin markdown-style headers:
###
h3 header.this first paragraph.
so need to:
- skip line begins 1 or more
#
symbols. - match first string ending in double line break.
in other words, return 'this first paragraph' in both of examples above.
so far, i've tried many variations on:
"/(?s)(?:(?!\#))((?!(\r?\n){2}).)*+/
but can't return proper match.
where did go wrong in lookaround?
i'm doing in php (preg_match()), if makes difference.
thanks!
you try
"/(?sm)^[^#](?:(?!(?:\r\n|\r|\n){2}).)*/"
i enable multiline option using (?sm)
instead of (?s)
, start each check @ new line, may not starting #. , used \r\n|\r|\n
instead of \r?\n
because testing environment had funny line breaks =)
Comments
Post a Comment