0

我希望有人可以帮助我解决这个正则表达式。我只用它来收集字符串中的单个单词,所以我不确定如何处理多行以及看起来像 ASCII 字符的内容。

这是文本块:

Information       - RETAILEAITRT00003 - Traitement        - Processing        - --->  Recovery from 05/09/2012 at 09:17:50 AM 

Information       - RETAILEAITRT00020 - Traitement        - Processing        - --->  Information recovery starts on 05/09/2012 at 09:17:50 AM 

Information       - RETAILEAITRT00021 - Traitement        - Processing        - ---->  File processing: C:\Program Files (x86)\Prog\Prog RIT\Web Orders\live\Prog Import\Order_110039354.tab
Information       - RETAILEAITRT00005 - Traitement        - Processing        - --->  End of information recovery on 05/09/2012 at 09:17:51 AM 
Information       - RETAILEAITRT00006 - Traitement        - Processing        -    -> 6 records read 
Information       - RETAILEAITRT00008 - Traitement        - Processing        -    -> 6 records processed 
Information       - RETAILEAITRT00010 - Traitement        - Processing        -    -> 6 integrated records 
Information       - RETAILEAITRT00015 - Traitement        - Processing        -    ->  No integration errors 

Information       - RETAILEAITRT00020 - Traitement        - Processing        - --->  Information recovery starts on 05/09/2012 at 09:17:51 AM 

Information       - RETAILEAITRT00021 - Traitement        - Processing        - ---->  File processing: C:\Program Files (x86)\Prog\Prog RIT\Web Orders\live\Prog Import\Order_110039355.tab
Third-party       -  : La raison sociale doit �tre renseign�e 
Third-party       - _SHIP : La raison sociale doit �tre renseign�e 
Erreur            - RETAILEAIDOC00008 - Document          - Document          - address The internal reference enables the recovery of a document. It is mandatory 
Erreur            - RETAILEAIDOC00008 - Document          - Document          - address The internal reference enables the recovery of a document. It is mandatory 
Information       - RETAILEAITRT00005 - Traitement        - Processing        - --->  End of information recovery on 05/09/2012 at 09:17:52 AM 
Information       - RETAILEAITRT00006 - Traitement        - Processing        -    -> 4 records read 
Information       - RETAILEAITRT00008 - Traitement        - Processing        -    -> 4 records processed 
Information       - RETAILEAITRT00012 - Traitement        - Processing        -    ->  No records integrated 
Information       - RETAILEAITRT00013 - Traitement        - Processing        -    -> 4 records contain errors 

Information       - RETAILEAITRT00003 - Traitement        - Processing        - --->  Recovery from 05/09/2012 at 09:33:03 AM 

Information       - RETAILEAITRT00020 - Traitement        - Processing        - --->  Information recovery starts on 05/09/2012 at 09:33:03 AM 

Information       - RETAILEAITRT00021 - Traitement        - Processing        - ---->  File processing: C:\Program Files (x86)\Prog\Prog RIT\Web Orders\live\Prog Import\Order_110039356.tab
Information       - RETAILEAITRT00005 - Traitement        - Processing        - --->  End of information recovery on 05/09/2012 at 09:33:05 AM 
Information       - RETAILEAITRT00006 - Traitement        - Processing        -    -> 6 records read 
Information       - RETAILEAITRT00008 - Traitement        - Processing        -    -> 6 records processed 
Information       - RETAILEAITRT00010 - Traitement        - Processing        -    -> 6 integrated records 
Information       - RETAILEAITRT00015 - Traitement        - Processing        -    ->  No integration errors 

Information       - RETAILEAITRT00020 - Traitement        - Processing        - --->  Information recovery starts on 05/09/2012 at 09:33:05 AM 

Information       - RETAILEAITRT00021 - Traitement        - Processing        - ---->  File processing: C:\Program Files (x86)\Prog\Prog RIT\Web Orders\live\Prog Import\Order_110039357.tab
Information       - RETAILEAITRT00005 - Traitement        - Processing        - --->  End of information recovery on 05/09/2012 at 09:33:06 AM 
Information       - RETAILEAITRT00006 - Traitement        - Processing        -    -> 6 records read 
Information       - RETAILEAITRT00008 - Traitement        - Processing        -    -> 6 records processed 
Information       - RETAILEAITRT00010 - Traitement        - Processing        -    -> 6 integrated records 
Information       - RETAILEAITRT00015 - Traitement        - Processing        -    ->  No integration errors

但是,我只想要这个部分:

Information       - RETAILEAITRT00020 - Traitement        - Processing        - --->  Information recovery starts on 05/09/2012 at 09:17:51 AM 

Information       - RETAILEAITRT00021 - Traitement        - Processing        - ---->  File processing: C:\Program Files (x86)\Prog\Prog RIT\Web Orders\live\Prog Import\Order_110039355.tab
Third-party       -  : La raison sociale doit �tre renseign�e 
Third-party       - _SHIP : La raison sociale doit �tre renseign�e 
Erreur            - RETAILEAIDOC00008 - Document          - Document          - address The internal reference enables the recovery of a document. It is mandatory 
Erreur            - RETAILEAIDOC00008 - Document          - Document          - address The internal reference enables the recovery of a document. It is mandatory 
Information       - RETAILEAITRT00005 - Traitement        - Processing        - --->  End of information recovery on 05/09/2012 at 09:17:52 AM 
Information       - RETAILEAITRT00006 - Traitement        - Processing        -    -> 4 records read 
Information       - RETAILEAITRT00008 - Traitement        - Processing        -    -> 4 records processed 
Information       - RETAILEAITRT00012 - Traitement        - Processing        -    ->  No records integrated 
Information       - RETAILEAITRT00013 - Traitement        - Processing        -    -> 4 records contain errors 

还有一些特殊字符显示为奇怪的问号。我真的不知道从哪里开始。我想它必须寻找 ^Erreur,然后抓住它上面和下面的行,直到找到带有空格的 ^...?

谢谢

4

1 回答 1

0

我能够让它与以下正则表达式一起工作:

Information.+recovery starts.+\n\n(?:.+\n)+(?:Erreur.+\n)+(?:.+\n)+

注意:这需要使用“g”(全局)标志(在 JavaScript 中测试成功)。不确定您使用的是哪种语言,但它应该有一个等效的标志。

是的,它非常丑陋:)。这基本上就是它要寻找的东西:

  • 以“信息”开头并包含“恢复开始”字样的行
  • 后跟一个空行
  • 后跟至少一个通用行
  • 后跟至少一行以“Erreur”开头的行
  • 后跟任何连续的非空白行
于 2012-05-09T16:04:05.340 回答