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](http://www.hollywoodholt.com)
to

<a href="http://www.hollywoodholt.com">Hollywood Holt</a>
 

and a string like

*Hello world*
to

<strong>Hello world</strong>
 

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

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](http://www.hollywoodholt.com)"""
html = markdown.markdown(markdown_text)
answered May 20, 2019 by SDeb
• 13,300 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
924 views
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,720 points
2,018 views
0 votes
1 answer

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

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

answered Apr 18, 2018 in Python by Johnathon
• 9,090 points
641 views
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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,023 views
0 votes
1 answer
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,300 points
585 views
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,300 points
655 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP