p = regex.compile('<span([^>]*"pagebreak"> ?)</span>') return p.sub(r'<xxspan\1</xxspan>', match.group())