1

How do we remove or filter data using regex to remove data after an in between ? The starting point is the first date (date could be dynamic it is no the fixed) so for example 08/03/2020 and the endpoint is the last 3 in capslock string (which is also dynamic but only up to 3 characters in capital letters) for example TRU in the string below. And should ignore or remove all the data after that

Here is my current regex :

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

But it aint dynamic .

This is to be remove since this is already after the 08/03/2020 and TRU.

Any idea how we can design a regex for this one ? thank you. #data to be remove

  Processing
       Co-Applicant
       No inquiry records found."

#The String

"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."

#Expected output

   "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
7
  • I already have pointed out the solution I need , please remove that associated question
    – Mr Dave
    Sep 18, 2020 at 8:35
  • here is my current regex Regex.Match(text,"(?<=08/03/2020\s+)[\S\s]*?(?=TRU)").Value.Trim
    – Mr Dave
    Sep 18, 2020 at 8:58
  • Please add this detail to the question and explain what is wrong with it. You write that "date could be dynamic", why do you hardcode it in the pattern? Sep 18, 2020 at 9:03
  • cause I dont know how to make it dynamic
    – Mr Dave
    Sep 18, 2020 at 9:07
  • I guess you want (?ms)^\d{2}/\d{2}/\d{4}\s[\S\s]*TRU$ (demo) Sep 18, 2020 at 9:18

1 Answer 1

1

You can use

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

See the regex demo

Details

  • (?ms) - RegexOptions.Multiline (^ matches line start and $ matches line end positions now) and RegexOptions.Singleline (. now also matches newline chars) inline modifers
  • \A - start of a string
  • (?:\d{2}/\d{2}/\d{2}(?:\d{2})?|−−DATE−−) - two digits, /, two digits, / and two or four digits or −−DATE−− string
  • \s - a whitespace
  • .* - any zero or more chars, as many as possible
  • \s - a whitespace
  • [A-Z]{3} - three uppercase ASCII letters (\p{Lu}{3} matches three uppercase letters from any language)
  • $ - end of a line.
10
  • Sir it did no longer work when the sample data is this
    – Mr Dave
    Sep 18, 2020 at 10:58
  • @MrDave Use (?ms)^\d{2}/\d{2}/\d{2}(?:\d{2})?\s.*\s\p{Lu}{3}$ (demo). Sep 18, 2020 at 10:59
  • some of the mode modifier is not supported sir I am using uipath , can you put or test that in this website sir regexr.com ?
    – Mr Dave
    Sep 18, 2020 at 11:09
  • @MrDave I won't use regexr, it is not user-friendly and less powerful than regex101 (only supports JavaScript and PCRE regex flavors). You are using the regex in UIPath that supports all the inline modifiers I am using in the answer. Sep 18, 2020 at 11:10
  • By the way sir , I am so sorry , this is by the way the original format of data from the ouput regex101.com/r/73wsdP/9
    – Mr Dave
    Sep 18, 2020 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.