ruby的正则表达式-scan方法
irb(main):001:0> str_vps=%Q{viewpoint_ids: [{"id":"260e053b-d728-4785-888d-eb4f1ca0a194","name":"全 局管综视点"},{"id":"7a1baa69-baab-434f-bcf0-aa885ab07ed4","name":"管综细部"},{"id":"441d05a2-bcc6-4e19-8eb7-f239934f395c","name":"空调机组"}]}
=> "viewpoint_ids: [{\"id\":\"260e053b-d728-4785-888d-eb4f1ca0a194\",\"name\":\"全局管综视点\"},{\"id\":\"7a1baa69-baab-434f-bcf0-aa885ab07ed4\",\"name\":\"管综细部\"},{\"id\":\"441d05a2-bcc6-4e19-8eb7-f239934f395c\",\"name\":\"空调机组\"}]"
irb(main):018:0> str_vps.scan(/id\":\"([^\"]*?)\",\"name\":\"([^\"]*?)\"}/) do |matched|
irb(main):019:1* p matched
irb(main):020:1> end
["260e053b-d728-4785-888d-eb4f1ca0a194", "全局管综视点"]
["7a1baa69-baab-434f-bcf0-aa885ab07ed4", "管综细部"]
["441d05a2-bcc6-4e19-8eb7-f239934f395c", "空调机组"]
=> "viewpoint_ids: [{\"id\":\"260e053b-d728-4785-888d-eb4f1ca0a194\",\"name\":\"全局管综视点\"},{\"id\":\"7a1baa69-baab-434f-bcf0-aa885ab07ed4\",\"name\":\"管综细部\"},{\"id\":\"441d05a2-bcc6-4e19-8eb7-f239934f395c\",\"name\":\"空调机组\"}]"
利用scan方法,将将视点的id,name属性匹配出来。