4

I'm not new to Python but a complete newbie with regular expressions (on my to do list)

I am trying to use python re to convert a string such as

[Hollywood Holt](http://www.hollywoodholt.com)

to

<a href="http://www.hollywoodholt.com">Hollywood Holt</a>

and a string like

*Hello world*

to

<strong>Hello world</strong>

1 Answer 1

12

Why are you bothering to use a regex? Your content is Markdown, why not simply take the string and run it through the markdown module?

First, make sure Markdown is installed. It has a dependancy on ElementTree so easy_install the two of them as follows. If you're running Windows, you can use the Windows installer instead.

easy_install ElementTree
easy_install Markdown

To use the Markdown module and convert your string to html simply do the following (tripple quotes are used for literal strings):

import markdown
markdown_text = """[Hollywood Holt](http://www.hollywoodholt.com)"""
html = markdown.markdown(markdown_text)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.