1
halfcrazy 2016-11-30 14:11:06 +08:00
```python
# -*- coding: utf-8 -*- import re pattern = "</?(\w+)>" txt = "<DIV>Windows XP</DIV><A>Windows XP</A><script>Windows XP</script>" def _sub(matchobj): return matchobj.group(0).replace(matchobj.group(1), matchobj.group(1).lower()) print(re.sub(pattern, _sub, txt)) ``` |
2
halfcrazy 2016-11-30 14:22:56 +08:00
@halfcrazy 考虑到存在单标签的情况。正则式需要修改一下`pattern = "</?(\w+)(?:[\s\S])*?/?>"`
|