zoukankan      html  css  js  c++  java
  • 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属性匹配出来。

  • 相关阅读:
    JavaScript基础
    Dao的扩展
    错题解析
    实现windows程序的数据绑定
    C#第三章
    第二章
    初始windows程序
    使用ADO.NET查询和操作数据
    使用ADO.NET访问数据库
    4.计算机层次与编程语言
  • 原文地址:https://www.cnblogs.com/BaiGuodong/p/4755368.html
Copyright © 2011-2022 走看看