1

I want to extract the number '123' from this:

<div class="f_right" style="padding-top:5px;">123</div>

What regular expression should I use? How can I extract just the number, without the wrapping <div>?

Kobi
  • 135,331
  • 41
  • 252
  • 292
Nirmal
  • 13
  • 2
  • 2
    [Don't use regex when dealing with HTML](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags). – darioo Jan 10 '11 at 10:21
  • 1
    Please explain what environment you are in. What programming language di you use, where does the HTML come from? – Tomalak Jan 10 '11 at 10:23
  • You need to be more specific about what situations you're wanting to match numbers in. The regular expression `/123/` will extract the number 123 from that string, but I doubt that's what you're after. Similarly, `/
    (...)/` will extract 123, but that's probably not going to catch many of the situations you're after.
    – Gareth Jan 10 '11 at 10:26

1 Answers1

1

@dario is right but if you want to do it this might work:

For yahoo pipes it should be like this.

<div class=".*?" style=".*?">(\d+)<\/div>

$1 will be your match

Mihai Toader
  • 12,041
  • 1
  • 29
  • 33
  • Don't forget to escape the slash - `` -> `<\/div>`, then it is at at least passable. `:)` – Kobi Jan 10 '11 at 10:24
  • Thank you :). It should have been escaped :( – Mihai Toader Jan 10 '11 at 10:26
  • Thanks a lot guys, I am using Yahoo Pipes, but its not giving me '123' but the entire string again, btw i am using $1 for (\d+) for match – Nirmal Jan 10 '11 at 10:29
  • works for me: http://pipes.yahoo.com/pipes/pipe.run?_id=f00101993e2589ad703e3d54ca3058e7&_render=json . Make sure to ignore / at the beginning and end of the regex when using in yahoo pipes. Updated the regex to be usable on Yahoo – Mihai Toader Jan 10 '11 at 10:35