0

例如,如果我有这一段:

paragraph = "Peter Piper picked a peck of pickled peppers;" +
"A peck of pickled peppers Peter Piper picked;" + 
"If Peter Piper picked a peck of pickled peppers, +
"Where's the peck of pickled peppers Peter Piper picked?"

我有这个正则表达式字符串:

strRegex = "[[:<:]]pick.*[[:>:]]" # match pick/picked/pickled

我如何使它适合正则表达式的所有单词都是BOLD

请以 django 视图形式给我建议。谢谢!

4

1 回答 1

0

替换它:

import re
re.sub(r"(.*)it(.*)", r"\1<b>it</b>\2", "Bold it!")
'Bold <b>it</b>!'
于 2013-02-26T12:48:49.557 回答