Python Regex Search And Replace

0 votes
I have been using Python since some time now but a complete newbie with regular expressions.

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

[Hollywood Holt](

<a href="">Hollywood Holt</a>

and a string like

*Hello world*

<strong>Hello world</strong>

Can anyone help me? How do I do this?
May 20, 2019 in Python by ana1504.k
• 7,900 points

1 answer to this question.

0 votes
You need not use a regex. Your content is Markdown and you can 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]("""
html = markdown.markdown(markdown_text)
answered May 20, 2019 by SDeb
• 13,270 points

Related Questions In Python

+4 votes
6 answers

Substring search in Python

Use the "in" operator in python" if "substring" ...READ MORE

answered Apr 13, 2018 in Python by Nietzsche's daemon
• 4,260 points
0 votes
1 answer

How can I find out the index of an element from row and column in Python?

You probably want to use np.ravel_multi_index: [code] import numpy ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,780 points
0 votes
1 answer

what are "and" and "or" operators in Python?

AND - True if both the operands ...READ MORE

answered Apr 17, 2018 in Python by Johnathon
• 9,090 points
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,033 views
0 votes
0 answers
0 votes
1 answer

.replace() regex in Python

No,  .replace() does not support regex. Regular expressions ...READ MORE

answered Nov 26, 2018 in Python by SDeb
• 13,270 points
0 votes
1 answer

How is Python 2.7.3 and Python 3.3 different?

raw_input() is not used in Python 3. Use input()  ...READ MORE

answered Sep 12, 2018 in Python by SDeb
• 13,270 points