import re

tag_header = re.compile(r'<h(\d).*>(.+)</h\d>')
source = """
<p>これはpタグ</p>
<h2>これはh2</h2>
<h3>これはh3</h3>
<h2 title="hoge">hoge</h2>
あああああああ
いいいいいいい
"""


def convert_header(m):
    count = int(m.group(1))
    content = m.group(2)
    return "#" * count + " " + content


result = tag_header.sub(convert_header, source)
result = re.sub(r"<p>", "-ppp-", result)
result = re.sub(r"</p>", "\n", result)
print(result)

31caed78eb4e71c6c65bd94e5fe7556600539697
<mask token>


def convert_header(m):
    count = int(m.group(1))
    content = m.group(2)
    return '#' * count + ' ' + content


<mask token>

<mask token>


def convert_header(m):
    count = int(m.group(1))
    content = m.group(2)
    return '#' * count + ' ' + content


<mask token>
print(result)

<mask token>
tag_header = re.compile('<h(\\d).*>(.+)</h\\d>')
source = """
<p>これはpタグ</p>
<h2>これはh2</h2>
<h3>これはh3</h3>
<h2 title="hoge">hoge</h2>
あああああああ
いいいいいいい
"""


def convert_header(m):
    count = int(m.group(1))
    content = m.group(2)
    return '#' * count + ' ' + content


result = tag_header.sub(convert_header, source)
result = re.sub('<p>', '-ppp-', result)
result = re.sub('</p>', '\n', result)
print(result)

import re
tag_header = re.compile('<h(\\d).*>(.+)</h\\d>')
source = """
<p>これはpタグ</p>
<h2>これはh2</h2>
<h3>これはh3</h3>
<h2 title="hoge">hoge</h2>
あああああああ
いいいいいいい
"""


def convert_header(m):
    count = int(m.group(1))
    content = m.group(2)
    return '#' * count + ' ' + content


result = tag_header.sub(convert_header, source)
result = re.sub('<p>', '-ppp-', result)
result = re.sub('</p>', '\n', result)
print(result)

import re

tag_header = re.compile(r'<h(\d).*>(.+)</h\d>')
source = """
<p>これはpタグ</p>
<h2>これはh2</h2>
<h3>これはh3</h3>
<h2 title="hoge">hoge</h2>
あああああああ
いいいいいいい
"""


def convert_header(m):
    count = int(m.group(1))
    content = m.group(2)
    return "#" * count + " " + content


result = tag_header.sub(convert_header, source)
result = re.sub(r"<p>", "-ppp-", result)
result = re.sub(r"</p>", "\n", result)
print(result)
