using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(?<!\\) # Check it was not escaped with a \
(?<img_all>
\!\[(?<img_alt>.+?)\] # image alternative text, i.e. the text used when the image does not
(?:
(?:
[ ]? # possibly followed by some spaces
(?:\n[ ]*)? # and a new line with some space
\[(?<img_id>.*?)\] # with the link id in brackets, but may be empty
)
|
(?:
(?:
\(
[ \t]*
<(?<img_url> # link url within <>; or
.+?
)>
[ \t]* # possibly followed by some spaces or tabs
(?:
(?<img_title_container>['""]) # Title is surrounded ether by double or single quotes
(?<img_title>.*?) # actual title, but could be empty as in ""
\g{img_title_container} # make the sure enclosing mark balance
)?
[ \t]*
\)
)
|
(?:
\(
[ \t]*
(?<img_url> # link url within <>; or
(?:((?![""']).)*+|.*)
)
[ \t]*
(?:
(?<img_title_container>['""]) # Title is surrounded ether by double or single quotes
(?<img_title>.*?) # actual title, but could be empty as in ""
\g{img_title_container} # make the sure enclosing mark balance
)?
[ \t]*
\)
)
)
)
)";
string input = @"
Inline within a paragraph: .
.jpg'Title here')
.jpg ""With title"") some text after

";
RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx