I have the tag:
val = "<a href=\"https://mobile.twitter.com\" rel=\"nofollow\">Mobile Web</a>"
In my test:
val[/(>.*<)/]
The return:
>Mobile Web<
I want return the text:
Mobile Web
I have the tag:
val = "<a href=\"https://mobile.twitter.com\" rel=\"nofollow\">Mobile Web</a>"
In my test:
val[/(>.*<)/]
The return:
>Mobile Web<
I want return the text:
Mobile Web
You can parse it with Nokogiri:
require 'nokogiri'
html = '<a href="https://mobile.twitter.com" rel="nofollow">Mobile Web</a>'
elem = Nokogiri(html)
puts elem.text
you can use match and select the parts you want with the parenthesis
/>(.*)</.match(val)[1]
I would use a html parsing library like hpricot or nokogiri for html parsing though because there can be a lot of corner cases with regex that aren't apparent until after it's running in production somewhere for months and breaks!
require 'nokogiri'
html = '<a href="https://mobile.twitter.com" rel="nofollow">Mobile Web</a>'
elem = Nokogiri::HTML::DocumentFragment.parse(html).child
p elem.text #=> Mobile Web