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

Hello friend ~
I want to get 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? Thanks ~

+3
source share
2 answers

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

  • <[^>]*> - math thiw first tag "<...>"
  • ([^<]*)- grab the text to open the next tag "<...> some text <...>"

how to apply it to ruby ​​- i don't know

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

+4
source

A regular expression that captures eternity between the first and second pair of angle brackets looks like

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

.

, , , HTML JavaScript.

0

Source: https://habr.com/ru/post/1789004/


All Articles