How to write a regular expression in Python?

0 votes
I want to write a simple regular expression in Python that extracts a number from HTML. The HTML sample is

Your number is <b>999</b>. So I want to extract only 999 from this. How to do it?
Jul 30, 2019 in Python by Neel
• 3,010 points
103 views

1 answer to this question.

0 votes

The following code should be able to do it. This will capture only 999 from the tag.

a = "Your number is <b>999</b>"
import re 
m = re.search(r"\d+", a)
m.group()
answered Jul 30, 2019 by Arvind
• 2,980 points

Related Questions In Python

+1 vote
0 answers

how to match the following string without a regular expression in python

abc_pqr_0_114_004.xxx ab_pq_04_114.xxx READ MORE

Dec 17, 2019 in Python by Rajesh Babu
• 130 points
171 views
0 votes
1 answer

How can I write code to find a palindrome in python without using string functions?

In Logic 1, try if i<int(length/2): instead of if i<int((length/2+1)): In ...READ MORE

answered Jan 16, 2019 in Python by charlie_brown
• 7,760 points
6,501 views
0 votes
1 answer

How do I check if input string is a valid regular expression or not in Python?

Hi. Good question! Well, just like what ...READ MORE

answered Feb 12, 2019 in Python by Nymeria
• 3,540 points
2,626 views
0 votes
1 answer

how do i print only the last two letters in a string using regular expression in python?

$ to match the end of the ...READ MORE

answered Mar 15, 2019 in Python by Waseem
• 4,530 points
101 views
+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 944 views
0 votes
0 answers
+4 votes
6 answers
+1 vote
1 answer

How to install a module in Python 3.6 ?

If you are using Ubuntu then the ...READ MORE

answered Jun 25, 2019 in Python by Arvind
• 2,980 points
177 views
+1 vote
1 answer

How to convert records from csv to a list in Python?

If you are using Python 3.x then ...READ MORE

answered Jun 25, 2019 in Python by Arvind
• 2,980 points

edited Jun 26, 2019 by Kalgi 494 views