I want to convert the following text
This is a , here is another 
at
This is a , here is another 
In other words, I want to find all the paths to the images enclosed between the brackets (text in Markdown syntax) and replace them with other paths. A string containing the new path is returned as a separate function real_path.
I would like to do this using String#gsubin my block version. Currently my code is as follows:
re = /!\[.*?\]\((.*?)\)/
rel_content = content.gsub(re) do |path|
real_path(path)
end
The problem with this regex is that it will match , not just foto.jpeg. I also tried another regexen like (?>\!\[.*?\]\()(.*?)(?>\)), but to no avail.
My current workaround is to split the path and compile it later.
Ruby, , ?
. , Ruby regexen lookbehinds. , , , .. /(pre)(matching-part)(post)/, .
re = /(!\[.*?\]\()(.*?)(\))/
rel_content = content.gsub(re) do
$1 + real_path($2) + $3
end