java - 在两个标签之间以常规方式解析?

标签 java regex grails groovy

我想用 groovy 解析这个 Gstring :

格式类型:键、值。

   def txt = """ <Lane_Attributes>
                  ID,1
                  FovCount,600
                  FovCounted,598
                  ...
                  </Lane_Attributes> """

然后得到一张像这样的 map :

Map = [ID:1, FovCount:600, FovCounted:598]

我怎样才能:
- 提取标签和 ?,
之间的文本 - 并转换为 map ?

最佳答案

试试这个:

def map = [:]
txt.replaceAll('<.+>', '').trim().eachLine { line ->
   def parts = line.split(',')
   map[parts[0].trim()] = parts[1].trim().toInteger()
}

关于java - 在两个标签之间以常规方式解析?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2784652/

相关文章:

java - Dagger 2 : Multiple entries with same key

javascript - 正则表达式仅包含数字和 2 个特殊字符(仅包含空格)

c# - Javascript RegEx 不会工作,但在 c# 中工作(原子子表达式)

regex - 从查找搜索中排除未知数量的多个目录 (Unix)

grails - 在Grails中使用gson View 并返回null

java - 如何从jar中的属性构造HDFS的路径?

java - Core Java 这个简单语法有什么问题

java - PostgreSQL、pgAdmin、Java : How to make them all UTC?

mongodb - MongoDB的连接过多

grails - 为什么在 Grails 中使用 HibernateCriteriaBuilder 时收到 "Null value was assigned to a property of primitive type setter of"错误消息