Ok instead of printing the whole line:
<von_icd_code V="A00"/>
I only would like to extract the text between V="..", in this case A00
Ok instead of printing the whole line:
<von_icd_code V="A00"/>
I only would like to extract the text between V="..", in this case A00
scan
如果您只对单个事件感兴趣,这是错误的方法。通常,还必须检查是否找到了子字符串。
代码应如下所示
s = '<von_icd_code V="A00"/>'
if s =~ /V="([^"]*)"/
puts $~[1]
end
输出
A00
require 'nokogiri'
doc = Nokogiri::XML::Document.parse('<von_icd_code V="A00"/>')
doc.at("von_icd_code")["V"] # => "A00"
Like this:
'<von_icd_code V="A00"/>'.scan(/V="(.+)"/)[0][0]
=> "A00"