fork download
  1. import re
  2. def m(r, s):
  3. mtc = re.match(r, s)
  4. if mtc:
  5. return s
  6. return "false"
  7. def italic(s):
  8. if m(r'\*{2}[^\*]+\*{2}', s) == 'false':
  9. return re.sub(r'\*([^*]+)\*', r'<em>\1</em>', s)
  10. return s
  11. print(italic('my plain text'))
  12. print(italic('*my italic text*'))
  13. print(italic('**now it is bold**'))
Success #stdin #stdout 0.1s 10088KB
stdin
Standard input is empty
stdout
my plain text
<em>my italic text</em>
**now it is bold**