VvDPzZ
VvDPzZ

Reputation: 3095

how to get the content between the first html tag and the second html tag in ruby

Hi friend~
I want get the content between the first html tag and the second html tag.
for example <p>Hello <bold>world</bold>!</p> will return Hello

What should I do in Ruby?
Thank you~

Upvotes: 3

Views: 1438

Answers (2)

kolko
kolko

Reputation: 300

Regex will be: <[^>]*>([^<]*)

  1. <[^>]*> - math thiw first tag "<...>"
  2. ([^<]*) - capture text to open next tag "<...> some text <...>"

how apply him on Rubby - i dont know

look http://www.regular-expressions.info/ruby.html

Upvotes: 4

Jens
Jens

Reputation: 25593

A regular expression catching everthing between the first and the second pair of angle brackets lools like

/<.*?>(.*?)</m

The result will be in the first capturing group of the first match.

Note that this will probably fail on HTML comments and JavaScript.

Upvotes: 0

Related Questions