开发者

Markdown emphasis - re substitution

How would you implement Markddown's emphasis or bold with regular expressions?

Or how is it possible to substitute re \*\*(.*)\*\* with what is i开发者_运维百科nside ** **?


You can use re.sub():

import re

myRegex = re.compile(r"\*\*(.+?)\*\*")
string = "some **text** and some **more**"

output = myRegex.sub(r"\1", string)


I think Fantasizer has the right idea.

Additionally, you should take a look at the Python based Markdown Library

Specifically look through inlinepatterns.py to see how they match 'strong' (bold) and 'emphasis'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜