grep with python匹配html文件中引号内的字符串

时间:2013-07-18 21:43:09

标签: python html grep

我是grep的新手,我熟悉Python。我的问题是找到并替换引号内的每个字符串,如“text”by< em> text< / em>

源文件具有html格式

由于

1 个答案:

答案 0 :(得分:1)

那就是诀窍

import re

s = '"text" "some"'
res = re.subn('"([^"]*)"', '<em>\\1</em>', s)[0]