我有标签:
val = "<a href=\"https://mobile.twitter.com\" rel=\"nofollow\">Mobile Web</a>"
Run Code Online (Sandbox Code Playgroud)
在我的测试中:
val[/(>.*<)/]
Run Code Online (Sandbox Code Playgroud)
回报:
>Mobile Web<
Run Code Online (Sandbox Code Playgroud)
我想要返回文字:
Mobile Web
Run Code Online (Sandbox Code Playgroud)
您可以使用Nokogiri解析它:
require 'nokogiri'
html = '<a href="https://mobile.twitter.com" rel="nofollow">Mobile Web</a>'
elem = Nokogiri(html)
puts elem.text
Run Code Online (Sandbox Code Playgroud)