$re = '/(?:(?<=^\n)|(?<=\A)) # Needs 1 or more new lines or start of string
(?<para_all>
(?<para_prefix>[ ]{0,3}) # Possibly some leading spaces, but less than a tab worth
(?<para_content>
(?:
(?! # some line content not starting with those exceptions
[[:blank:]\h]{0,3}
(?:
\*{1}[ \t]+ # a list
|
(?:\*(?:[ ]?\*){2,}) # a horizontal line
|
(?:\-*(?:[ ]?\-){2,}) # a horizontal line
|
(?:\_*(?:[ ]?\_){2,}) # a horizontal line
|
[>+-=\#]
|
\d+\. # ordered list
|
\`{3,} # code block
|
\~{3,} # code block extended
)
)
)
.+
(?!\n(?:[=-]+))
(?:\n|$)
)+
)/mx';
$str = '***This is strong and em.***
The quick brown fox
jumps over the lazy dog
Lorem Ipsum
I should match
- I should NOT match
Le sigh
> Why am I matching?
1. Nonononono!
* Aaaagh!
# Stahhhp!
Hello, World!
==
---
***
***
***
***
***
* * *
* * *
* * *
* * *
___
___
___
___
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php