0

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

4

3 回答 3

2

scan如果您只对单个事件感兴趣,这是错误的方法。通常,还必须检查是否找到了子字符串

代码应如下所示

s = '<von_icd_code V="A00"/>'

if s =~ /V="([^"]*)"/
  puts $~[1]
end

输出

A00
于 2013-08-10T10:31:17.880 回答
2

使用Nokogiri::XML::Document

require 'nokogiri'

doc = Nokogiri::XML::Document.parse('<von_icd_code V="A00"/>')
doc.at("von_icd_code")["V"] # => "A00"
于 2013-08-10T10:46:51.287 回答
1

Like this:

'<von_icd_code V="A00"/>'.scan(/V="(.+)"/)[0][0]
=> "A00"
于 2013-08-10T09:49:48.347 回答