-6

if i want to find every odds which has the following format - ( 1.64 - 2.38), how do i code regex?

 <td class="t-odds">
       1.64 - 2.38                 
      </td>

 re.findall(r'bets/.+?/.+?">(.+?)</a>',Tennis)
user4461365
  • 49
  • 1
  • 1
  • 6
  • 1
    Incomplete code. I failed to find an anchor tag. What's the value of variable `Tennis`? – Avinash Raj Aug 10 '15 at 16:06
  • 1
    You look like you're trying to use regex to parse HTML - don't. Use an HTML parser! – jonrsharpe Aug 10 '15 at 16:08
  • This problem becomes much more difficult if you want to match the representation of _all_ possible floats, such as `1e-10` and `nan` – Kevin Aug 10 '15 at 16:12
  • [People have gone insane](http://stackoverflow.com/a/1732454/103081) over parsing HTML with regex code. – Paul Aug 11 '15 at 06:54
  • I can't tell what the format is from this snippet. Is the td class name always "t-odds"? Could the odds be displayed as plain text instead of a table cell? The currently posted `re.findall` call doesn't provide any hints of what you want to do, either, though it should. The title says "float dash float" but there is no dash in the `re.findall` – Paul Aug 11 '15 at 06:58

1 Answers1

0

What you are looking for is probably this regex: (\d+\.\d+)\s\-\s(\d+.\d+)

But honestly, as @jonrsharpe and others have suggested in comments, what you should do is use an HTML parser. Not only is it safer, it is easier.

You can try a live demo of my regex here, on Regex101.com.

Asunez
  • 2,327
  • 1
  • 23
  • 46