1

我们如何使用正则表达式删除或过滤数据以在中间删除数据?起点是第一个日期(日期可以是动态的,它不是固定的),例如 08/03/2020,终点是大写字母字符串中的最后 3 个(这也是动态的,但大写字母最多只能包含 3 个字符) 例如下面字符串中的 TRU。并且应该在此之后忽略或删除所有数据

这是我当前的正则表达式:

Regex.Match(text,"(?<=08/03/2020\s+)[\S\s]*?(?=TRU)").Value.Trim

但它不是动态的。

这将被删除,因为这已经在 08/03/2020 和 TRU 之后。

知道我们如何为这个设计一个正则表达式吗?谢谢你。#要删除的数据

  Processing
       Co-Applicant
       No inquiry records found."

#字符串

"08/03/2020        NOVUS HOME                  Mortgage Company                                                     TRU
                     MORTGAGE
   07/08/2020        FACTUAL DATA                Mortgage Reporter                                                    XPN
   07/08/2020        FCTUALDATA                                                                                       EFX
   07/08/2020        NOVUS HOME                  Mortgage Company                                                     TRU
                     MORTGAGE
   07/07/2020        CROSSCOUNTRY                Mortgage Loan                                                        TRU
                     MORTGAG
   07/07/2020        FACTUAL DATA                Mortgage Reporter                                                    XPN
   07/07/2020        FCTUALDATA                                                                                       EFX
   05/21/2020        CAP ONE NA                  Bank Credit Card                                                     XPN
   05/21/2020        CAPITAL ONE                 Credit Card                                                          TRU
   05/21/2020        CAPITALONE                  Bank                                                                 EFX
   05/20/2020        CROSSCOUNTRY                Mortgage Loan                                                        TRU
                     MORTGAG
   05/20/2020        FACTUAL DATA                Mortgage Reporter                                                    XPN
   05/20/2020        FCTUALDATA                                                                                       EFX
   05/20/2020        FINGERHUT/WEBBANK           Finance Company                                                      XPN
   05/07/2020        EMS                                                                                              EFX
   05/07/2020        GROW FINANCIAL CREDI        Credit Bureau/Mortgage                                               TRU
                                                 Processing
   Co-Applicant
   No inquiry records found."

#预期输出

   "08/03/2020        NOVUS HOME                  Mortgage Company                                                     TRU
                         MORTGAGE
       07/08/2020        FACTUAL DATA                Mortgage Reporter                                                    XPN
       07/08/2020        FCTUALDATA                                                                                       EFX
       07/08/2020        NOVUS HOME                  Mortgage Company                                                     TRU
                         MORTGAGE
       07/07/2020        CROSSCOUNTRY                Mortgage Loan                                                        TRU
                         MORTGAG
       07/07/2020        FACTUAL DATA                Mortgage Reporter                                                    XPN
       07/07/2020        FCTUALDATA                                                                                       EFX
       05/21/2020        CAP ONE NA                  Bank Credit Card                                                     XPN
       05/21/2020        CAPITAL ONE                 Credit Card                                                          TRU
       05/21/2020        CAPITALONE                  Bank                                                                 EFX
       05/20/2020        CROSSCOUNTRY                Mortgage Loan                                                        TRU
                         MORTGAG
       05/20/2020        FACTUAL DATA                Mortgage Reporter                                                    XPN
       05/20/2020        FCTUALDATA                                                                                       EFX
       05/20/2020        FINGERHUT/WEBBANK           Finance Company                                                      XPN
       05/07/2020        EMS                                                                                              EFX
       05/07/2020        GROW FINANCIAL CREDI        Credit Bureau/Mortgage                                               TRU
4

1 回答 1

1

您可以使用

(?ms)\A(?:\d{2}/\d{2}/\d{2}(?:\d{2})?|−−DATE−−)\s.*\s\p{Lu}{3}$

查看正则表达式演示

细节

  • (?ms)- RegexOptions.Multiline(现在^匹配行开始和$行结束位置)和RegexOptions.Singleline.现在也匹配换行符)内联修饰符
  • \A- 字符串的开头
  • (?:\d{2}/\d{2}/\d{2}(?:\d{2})?|−−DATE−−)- 两位数, /, 两位数,/两位或四位数字或−−DATE−−字符串
  • \s- 一个空格
  • .*- 任何零个或多个字符,尽可能多
  • \s - 一个空格
  • [A-Z]{3}- 三个大写 ASCII 字母(\p{Lu}{3}匹配任何语言的三个大写字母)
  • $- 行尾。
于 2020-09-18T10:12:57.407 回答