首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何同时使用2个正则表达式从文件填充Map?

如何同时使用2个正则表达式从文件填充Map?
EN

Stack Overflow用户
提问于 2016-06-20 10:49:03
回答 1查看 56关注 0票数 0

我目前正在从一个.audit文件中填充一个列表,并将两部分信息提取到一个映射中。下面是文件的外观:

代码语言:javascript
复制
   type         : REGISTRY_SETTING
   description  : "1.9.56 Network security: Do not store LAN Manager hash value on next password change: Enabled"
   info         : "This control defines whether the LAN Manager (LM) hash value for the new password is stored when the password is changed."
   solution     : "Make sure 'Do not store LAN Manager hash value on next password change' is Enabled."
   reference    : "PCI-DSS|8.4,800-53|AC-3,800-53|SC-5,800-53|CM-7,800-53|CM-6,CCE|CCE-8937-5"
   see_also     : "https://benchmarks.cisecurity.org/tools2/windows/CIS_Microsoft_Windows_7_Benchmark_v1.2.0.pdf"
   value_type   : POLICY_DWORD
   reg_key      : "HKLM\System\CurrentControlSet\Control\Lsa"
   reg_item     : "NoLMHash"
   value_data   : 1



   type         : REGISTRY_SETTING
   description  : "1.13.3 Notify antivirus programs when opening attachments: Enabled"
   info         : "This control defines whether antivirus program to be notified when opening attachments."
   solution     : "Make sure 'Notify antivirus programs when opening attachments' is Enabled."
   reference    : "800-53|SI-3,PCI-DSS|5.1.1,CCE|CCE-10076-8,PCI-DSS|5.1"
   see_also     : "https://benchmarks.cisecurity.org/tools2/windows/CIS_Microsoft_Windows_7_Benchmark_v1.2.0.pdf"
   value_type   : POLICY_DWORD
   reg_key      : "HKU\Software\Microsoft\Windows\CurrentVersion\Policies\Attachments"
   reg_item     : "ScanWithAntiVirus"
   value_data   : 3
   reg_ignore_hku_users : "S-1-5-18,S-1-5-19,S-1-5-20"

我需要的地图是一个<description,value_data>格式,无论是否有任何东西在value_data之后,例如:

代码语言:javascript
复制
Key: "1.9.56 Network security: Do not store LAN Manager hash value on next password changed."

Value: 1 

下面是我用Map的键值填充Map的当前代码:

代码语言:javascript
复制
String descriptionString = Pattern.quote("description") + "(.*?)" + Pattern.quote("info");


Pattern descriptionPattern = Pattern.compile(descriptionString);


Matcher descriptionMatcher = descriptionPattern.matcher(auditContentList.get(i));


while(descriptionMatcher.find())
{
      System.out.println("Key found ");
      customItemMap.put(descriptionMatcher.group(1),"");
}

问题是我不能在任何给定的时间同时使用两个正则表达式来填充Map的相同索引。有没有更好的方法来做到这一点?

EN

回答 1

Stack Overflow用户

发布于 2016-06-20 19:46:34

对于您的样本数据,也许您应该尝试这样做:

代码语言:javascript
复制
description.*?"(.*?)"[\s\S]*?value_data.*?(\d+)

我已经用 [here]测试过了

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37914003

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档