-1

I am scraping data from a website and the tag contains the text 'ANSWER (1)'. My goal is to extract just the '1' from the string using regular expressions in python.

Is there a simple way to go about doing this?

Ryan
  • 57
  • 1
  • 5
  • 15
  • Please consider searching either this website or google first. This is the most basic form of Regular Expressions! e.g: ``([0-9]+)``. – James Mills May 21 '14 at 03:18
  • Can you please provide some of the input, what kind of tag it is in? – hwnd May 21 '14 at 03:19
  • The string is held within an H3 tag. I have the data extracted and stored into a string. So at this point, my goal would be to take the string and only extract the data in between the parenthesis. – Ryan May 21 '14 at 03:20
  • Not really sure why this is marked as duplicate. This is a regex question, not a beautiful soup question. – Ryan May 21 '14 at 03:21
  • The concept is the. Search this site for "Python Regular Expressions". Please consider posting more specific questions and do your homework. – James Mills May 21 '14 at 03:22
  • 1
    It's encouraged to use a parser such as BeautifulSoup, not regular expression. – hwnd May 21 '14 at 03:22

1 Answers1

0

Try this code:

import re
s = "ANSWER (1)"
print re.search(r".*\((\d)\)",s).group(1)
anirudh
  • 4,116
  • 2
  • 20
  • 35
  • This did work, thank you. I need to brush up on my knowledge of regular expressions. Thanks for the help – Ryan May 21 '14 at 03:28