If repl is a function, it is called for every non-overlapping occurrence of pattern. The function takes a single match object argument, and returns the replacement string.
下面是一个例子:
In [1]: import re
In [2]: def repl(m):
...: return '#' * len(m.group())
...:
In [3]: re.sub(r'<[^<>]*?>', repl,
...: '<o:LastSaved>2013-01-21T21:15:00Z</o:LastSaved>')
Out[3]: '#############2013-01-21T21:15:00Z##############'
^{} 接受函数作为替换:
下面是一个例子:
我使用的模式可能需要一些润色,我不确定匹配XML标记的标准解决方案是什么。但你明白了。在
相关问题 更多 >
编程相关推荐