I have a piece that already has some formatting. Now I need to convert this to a format so I can use the Wordpress API to send it to wordpress.
This is an example of my text:
'**H1: Some text**\n\nSome text as paragraph.\n\n**H2: A subheader**\n\nText from the subheader.\n\nA line break with some more text.\n\n**H2: Another sub hearder**\n\n**H3: A sub sub header
I tried this:
test = myFullText
header1 = re.findall('H1.*?ph.', test)
And
test = myFullText
header1 = re.findall('H1.*?\n\n.', test)
Both give me empty "header1"
More general question. I assume the findall function is the best approach for my use case. Or is there another option to achieve this. Like I mentioned. My ultimate goal is to create a Wordpress blogpost from this text.
Yes, it fine, Better you can use regular expressions Match headers with optional content following
headerpattern = r"\*\*(H\d): (.*?)\*\*"
headers = re.findall(header_pattern, test)