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'
精彩评论