Regex 多行正则表达式组匹配

Regex 多行正则表达式组匹配,regex,ms-access,vbscript,match,multiline,Regex,Ms Access,Vbscript,Match,Multiline,我正在尝试使用正则表达式解析模板格式 这是一个样本 Type of Change: Modify Metavance: None AutoSys : None Informatica Migration: None FTP Details: None Device/Server: DWEIH

我正在尝试使用正则表达式解析模板格式

这是一个样本

Type of Change:                 Modify
Metavance:                      None
AutoSys :                       None
Informatica Migration:          None
FTP Details:                    None
Device/Server:                  DWEIHPRD
DB Objects:                     Delete
                                 ARC_MEDICAL_CLAIM_DETAIL_FK1
DB Name:                        DWEIHPRD
Schema-Table(s):            UTIL
Interface(s):                     IF0515
Reports (RAPS):              None
Ancillary Systems:            None
基本上一切都很好

字段:数据可能是多行的,如上面的DB对象示例中所示

^(.+?):(.*)
非常接近我想要的,除了它只抓取DB对象的第一行。如果启用dotall,则所有内容都将匹配贪婪,并且所有内容都位于第一个字段结果中

字段和数据中的额外空白都会被优化,但如果这不是正则表达式的一部分,那也不是什么大问题

另一个麻烦是,我必须在access 97 vbscript中完成这项工作,因此它可能无法提供一些更好的现代正则表达式功能:

注意:这是一个丑陋的解决方案,但可能会对您有所帮助。正如@anubhava所建议的,可能存在非正则表达式解决方案。我只是不太了解VBA,无法说出它可能是什么

根据这篇VBScript for Microsoft Office支持lookaheads、lookbehinds和non-capturing的文章,文章的日期是2009年,但如果支持追溯到Access 97,我会非常惊讶,尽管我可能错了

通常情况下,我会使用lookaheads和非捕获组来实现这一点,但避免使用它们,因为它们不太可能在Office 97中得到支持。所以请注意,您只需忽略捕获组3,该组仅用于在多行匹配中测试可选的行尾字符。注意,这将只查找分布在两行的匹配项

^(.+):\s+(.+)(\r\n\s+(.+))*
note this has four capture groups, but you will ignore \3. Use \1, \2, and \4 (four will be empty for single line matches)
解释:

^         # beginning of line
(.+):     # capture one or more characters up to a colon
\s+(.+)   # skip past whitespace, then capture characters up to end of line
(         # open a capturing group (to be thrown away. See explanation above)
  \r\n\s+ # peek ahead to see if there are EOL characters followed by whitespace
  (.+)    # if we got this far, capture whatever characters come after the whitespace
)*        # and make this group optional (and you will ignore it anyway)

不需要。如果在vbscript解决方案中有其他易于实现的解决方案,也可以。