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!
==
---
***
***
***
***
***
* * *
* * *
* * *
* * *
___
___
___
___
'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html