re = /^(?!.*:\/\/)(?P<md>.*\.[mM][dD])?(?P<section>#.*)?$/m
str = 'We want to find relative markdown urls, we don\'t care about https or ftp:// type urls...
^(?:(?!(?:https?|ftp)://).*)(?P<md>\\.[mM][dD])(?P<section>#?.*)$
https://github.com/tomduck/pandoc-fignos
http://github.com/tomduck/pandoc-fignos
ftp://github.com/tomduck/pandoc-fignos
ftp://github.com/ tomduck/ pandoc-fignos
ftp:// github.com/ tomduck/ pandoc-fignos
ftps://github.com/tomduck/pandoc-fignos
www.google.ca
google.com
./ch0_1_images.md#fig:ch0_1_images-1
./ch0_1_images.md#fig:ch0_1_images-2
./ch0_2_equations.md#sec:ch0_2_equations-1
./ch0_2_equations.md#eq:ch0_2_equations-1
./ch0_2_equations.md#eq:ch0_2_equations-2
./ch0_2_equations.md
./hello world.md
#eq:ch0_2_equations-2
#eq:ch0_2_equations-2'
# 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