code_junkie

How does one parse simple inline markup (i.e. *bold*), in Python

Nov 14th, 2011
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. *bold*, /italics/, _underline_
  2.  
  3. Hello, *world*! Let's /go/.
  4.  
  5. Hello textbf{world}! Let's textit{go}.
  6.  
  7. >>> import re
  8. >>> str = "Hello, *world*! Let's /go/."
  9. >>> str = re.sub(r"*([^*]*)*", r"textbf{1}", str)
  10. >>> str = re.sub(r"/([^/]*)/", r"textit{1}", str)
  11. >>> str
  12. "Hello, textbf{world}! Let's textit{go}."
Add Comment
Please, Sign In to add comment