views:

563

answers:

1

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"&gt;Hollywood Holt</a>

and a string like

*Hello world*

to

<strong>Hello world</strong>
+11  A: 

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)
Soviut
+1 I'll give it to ya. ;)
Paolo Bergantino
great, thanks a lot!