The best way is to find the version of the Markdown library ported to any language you use (you did not specify in your question).
Now that you have clarified that you want STRONG and EM to be processed, and that you are using C #, I recommend that you take a look at Markdown. NET to see how these tags are implemented. As you can see, these are actually two expressions. Here is the code:
private string DoItalicsAndBold (string text) { // <strong> must go first: text = Regex.Replace (text, @"(\*\*|__) (?=\S) (.+?[*_]*) (?<=\S) \1", new MatchEvaluator (BoldEvaluator), RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline); // Then <em>: text = Regex.Replace (text, @"(\*|_) (?=\S) (.+?) (?<=\S) \1", new MatchEvaluator (ItalicsEvaluator), RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline); return text; } private string ItalicsEvaluator (Match match) { return string.Format ("<em>{0}</em>", match.Groups[2].Value); } private string BoldEvaluator (Match match) { return string.Format ("<strong>{0}</strong>", match.Groups[2].Value); }
Tim booker
source share