changing plaintext tags into HTML tags to display in browser in python
Question: ok so I'm writing a function in python which takes a text document which is
tagged with tags like ===, ==, ---, #text# etc. etc. (alot like wikipedia).
Now my program basically has to replace those with HTML tags such as &ndash,
&mdash, <>text etc. so that they can be displayed properly in a browser. This
is what i've got so far:

    
    
    def tag_change ():
        for () in range ()
        sub('--', '&ndash;')
        sub('---', '&mdash;')
        sub('''*''', '<i>*</i>')
        sub("'''*'''", '<b>*</b>')
        sub("==*==", "<h1>*</h1>")
        sub("#*#", "<li>*</li>")
    

Am I on the right track? Or is there something else I need to include? I'm
fairly new to this


Answer: Your best bet (if you want to write your own function and avoid using an
existing tool) is to use regex, which is simple enough

    
    
    import re
    
    def subst(text):
       str = '#text#'
       capture = re.search('#(.+)#', str)
       return '<li>'+ capture.group(1)+ '</li>'
    

I hope you get the idea you could also use patterns like '==(.+)==' and so
forth to capture what you want. You can view this post to learn more about
using re.search and re.match <http://stackoverflow.com/a/180993/2152321>

You can also learn more about regex pattern construction here
<http://www.tutorialspoint.com/python/python_reg_expressions.htm>

