Extract string inbetween 2 specific keyword using Regex

Hi there,

I am trying to extract specific text inbetween NATURE OF BUSINESS and LOAN GRADING from a string with text as shown below

Here is my code atm,
System.Text.RegularExpressions.Regex.Match(ExtractedPDF,"(?<=NATURE OF BUSINESS : ).?(?=\r\nLOAN GRADING : )").Value*

Example of text:
"LENDING UNIT : CBG-Commerce and Services Classified & Unrestricted\r\n(110)\r\nLEGAL ENTITY : asfFD NO : 110/2019/000301/RE\r\n\r\nasfFD - APPLICATION FOR ACCOMMODATION \r\n(Renewal) \r\n\r\n \r\n\r\nAA No : 110/2019/000301/RE\r\nApproving Authority : CM APP\r\nDate : 12-03-2019\r\n\r\n \r\n\r\nAA TYPE : Renewal\r\nAA STATUS : Renewal\r\nSTANDALONE : No\r\nPRODUCT / SCHEME : Others\r\nLENDING UNIT : CBG-Commerce and Services (110)\r\nBORROWER : SSS Pte Ltd\r\nNATURE OF BUSINESS : WHOLESALE OF LOGS, SAWN TIMBER, PLYWOOD AND RELATED\r\nPRODUCTS(46631)\r\nLOAN GRADING : Normal\r\n\r\n \r\n\r\nFinal AL CM APP\r\nAL Structure Beyond Fast Track Renewal\r\nBorrower Rating (BRR) 12 - Large Corporates\r\nFacility Rating (FRR) G\r\nExpected Loss (EL) SGD 14,016.63\r\n\r\n \r\n\r\nProjected Borrower RRWA (in 0.0 %\r\npercentage)\r\nActual Borrower RRWA 50.87 %\r\nActual Group RRWA 181.57 %\r\nDeposit Commission/ Other Income SGD 93838 per annum\r\n(S$) (contributed by non-borrowing\r\nentities within Borrower Group)\r\nActual RRWA information as at 31/03/2019\r\nRRWA = 0 denotes that RRWA cannot be calculated / not available\r\n\r\n \r\n\r\nAPPLICATION CHECKLIST SUMMARY\r\n \r\n\r\nSection Applicable\r\nGroup Annual Sales Checklist Yes\r\nSection 27 / MAS Notice 639A No\r\nSection 29 / MAS Notice 639 No\r\nMAS Notice 757 No\r\nCredit Policy Exceptions/Guidelines Yes\r\nSection 35 No\r\n\r\nRENEWAL CONDITIONS\r\n \r\n\r\nCONDITIONS REMARKS\r\n\r\ni) No deterioration in credit worthiness of the borrower ( Rated and Met\r\nUnrated AAs )\r\nFor rated AAs,deterioration in credit worthiness includes :\r\n- Rating category migrated from Moderate (BRR 11-15) to High (BRR\r\n16-21) ; or\r\n- Internal credit rating deteriorated by 3 or more notches\r\nii) No changes in the original terms and conditions (Security, Packaging & Met\r\nCovenants)\r\n\r\nCREDIT EXCEPTION CHECKLIST\r\n \r\nPage 1 of 15

Hi,

Hope the following expression helps you.

System.Text.RegularExpressions.Regex.Match(ExtractedPDF,"(?<=NATURE OF BUSINESS : )[\s\S]*?(?=\r\nLOAN GRADING : )").Value

Regards,

1 Like

Hello

Use this Regex

System.Text.RegularExpressions.Regex.Match(ExtractedPDF,“(?<=NATURE OF BUSINESS : ).*(?=LOAN GRADING)”).Value

Thanks
@alanthegenerous

Tried both way but it doesn’t work. It shown up as blank when i assign my variables to it.

Hi,

In my side, it works. Can you check the following sample? The data seems same as yours I think.

Sample20200219-1.zip (10.5 KB)

Regards,

Its Working for me

System.Text.RegularExpressions.Regex.Match(test,“(?<=NATURE OF BUSINESS : ).*(?=LOAN GRADING)”).ToString

Assign it into String Variable

Thanks
@alanthegenerous

Hi all,
It’s working now. Thanks a lot for your prompt help!

1 Like

Mark its as Solution

Thanks
@alanthegenerous