协助正则表达

时间:2017-10-06 15:48:08

标签: regex search

我有一个文件,其格式如下所示。 #ADDBANK是每条记录的标题,每条记录可能有0行或多行以//错误开头!

我需要一个正则表达式来识别包含1个或多个以//错误开头的行的所有记录(以#ADDBANK开头)!并从该记录返回以下行:

  • 包含#ADDBANK
  • 的行
  • 相应记录中以customerNumber
  • 开头的行
  • 记录中以// error!
  • 开头的每一行

例如,对于具有以下两个样本记录的文件的正则表达式的结果,将如下所示。那里的任何正规表达专家都可以借给我一个手?

结果

#ADDBANK
customerNumber=10427856
//error!-error=SP02195:account.paymentSummary.statementFormat is not required when account.paymentSummary.statementIndicator is Suppress Statement-Create Billing. error=SP02195:account.paymentSummary.statementFormat is not required when account.paymentSummary.statementIndicator is Suppress Statement-Create Billing.
//error!-error=ufaEvent.process exception : account.paymentSummary.statementFormat is not required when account.paymentSummary.statementIndicator is Suppress Statement-Create Billing. error=ufaEvent.process exception : account.paymentSummary.statementFormat is not required when account.paymentSummary.statementIndicator is Suppress Statement-Create Billing.

示例文件

#ADDBANK
customerNumber=10427856
bankruptcy.filingDate=2015-12-10
bankruptcy.bankruptcyStatus=CONFIRM
bankruptcy.bankruptcyStatusDate=2015-12-10
bankruptcy.proofOfClaimType=FILINHOU
bankruptcy.proofOfClaimFilingDate=2015-12-31
bankruptcy.confirmationDate=2016-02-18
bankruptcy.caseNumber=19-10832
bankruptcy.chapterFiled=CHAPTER13
bankruptcy.creditUnionAgency=Virginia Eastern
bankruptcy.bankruptcyUAFAttributes.uafString9=0
bankruptcy.bankruptcyUAFAttributes.uafString6=ST LOUIS
bankruptcy.bankruptcyUAFAttributes.uafString4=JOHN DOE JR
bankruptcy.bankruptcyUAFAttributes.uafString13=0
bankruptcy.bankruptcyUAFAttributes.uafString8=63143
bankruptcy.bankruptcyUAFAttributes.uafDate5=2016-09-07
bankruptcy.bankruptcyUAFAttributes.uafString7=MO
bankruptcy.bankruptcyUAFAttributes.uafString11=0
bankruptcy.bankruptcyUAFAttributes.uafString5=PO BOX 430908
//error!-error=SP02195:account.paymentSummary.statementFormat is not required when account.paymentSummary.statementIndicator is Suppress Statement-Create Billing. error=SP02195:account.paymentSummary.statementFormat is not required when account.paymentSummary.statementIndicator is Suppress Statement-Create Billing.
//error!-error=ufaEvent.process exception : account.paymentSummary.statementFormat is not required when account.paymentSummary.statementIndicator is Suppress Statement-Create Billing. error=ufaEvent.process exception : account.paymentSummary.statementFormat is not required when account.paymentSummary.statementIndicator is Suppress Statement-Create Billing.

#ADDBANK
customerNumber=10428256
bankruptcy.filingDate=2010-09-06
bankruptcy.bankruptcyStatusDate=2017-10-03
bankruptcy.bankruptcyStatus=FILED
bankruptcy.confirmationDate=2012-01-12
bankruptcy.chapterFiled=CHAPTER13
bankruptcy.creditUnionAgency=Western
bankruptcy.bankruptcyUAFAttributes.uafString6=Kansas City
bankruptcy.bankruptcyUAFAttributes.uafString4=Bob Martin
bankruptcy.bankruptcyUAFAttributes.uafString9=0
bankruptcy.bankruptcyUAFAttributes.uafString3=NO
bankruptcy.bankruptcyUAFAttributes.uafString8=64106
bankruptcy.bankruptcyUAFAttributes.uafString7=MO
bankruptcy.bankruptcyUAFAttributes.uafDate5=2011-01-05
bankruptcy.bankruptcyUAFAttributes.uafString5=818 Test Blvd
bankruptcy.bankruptcyUAFAttributes.uafString11=0
bankruptcy.bankruptcyUAFAttributes.uafString13=0

1 个答案:

答案 0 :(得分:1)

如果您希望匹配这些行,您只需匹配每行的结尾即可。使用这个正则表达式

#ADDBANK|customerNumber.*|\/\/error.*

您将匹配记录中的所有必需行。但是使用这个正则表达式,你将不得不遍历所有匹配,以收集所有匹配的行。