re = /\[.*\]\((?!http:)(?!.+\.md).+\)/m
str = 'dfg [link text 3](http://external-link...md) fgdfg
dfg [link text 3](http://external-link/file.ext) dfg
dfg [link text 3](http://external-link/file.) dfg
dfg [link text 3](http://external-link) dfg
dfg [link text 1](internal-link) dfgdg
dfg [link text 1](internal-link.) dfgdg
dfg [link text 2](internal-link-2.md) dfgdg
dfg [link text 2](internal-link-2.mdsdfsdf) dfgdg
'
# 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