How to Extract Amount in text file using REGEX

Info.txt (1.3 KB)
In this text file i need to extract amount $300.
After “In-Network: (Other than Tier 2 & 3)” keyword.
The key word is constant, but the amount is dynamic.
How can we extract only the amount in this whole txt file? Using Regex.
I need o/p “$300”

Hi @Vicky_K,

Kindly try this regex pattern.

(?<=\(Other than Tier 2 & 3\) - subject to ).*?(?= copay)

Regards
Ömer

Hi @Vicky_K ,

Take a look at the below Regex Expression :

(?<=In-Network: \(Other than Tier 2 & 3\)).*?(\$[\d+.,]+)

Let us know if there other keywords that we can rely on , so that we can make the regex more concrete.

Hi @Vicky_K

How about this expression?

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=\ssubject\sto\s).*?(?= copay)").Tostring

Regards
Gokul

Hello @Vicky_K

Kindly try this
(?<=\(Other than Tier 2 & 3\)\s\W\ssubject\sto\s)[$\d]+

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=\(Other than Tier 2 & 3\)\s\W\ssubject\sto\s)[$\d]+").Tostring

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=\(Other than Tier 2 & 3\)\s\W\ssubject\sto\s)[$\d.]+").Tostring

(?<=subject\sto\s)[$\d.]+

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=subject\sto\s)[$\d.]+").Tostring

Hey gokul Thanks for reply,
But the key word extended the words like below,
In-Network: (Other than Tier 2 & 3, In-State and Other Medical/Surgical Facility (Non-Psychiatric) or Outpatient) - subject to $600.00 copay (applies to OOP) each visit for Contraceptives, Diagnostic Lab and Pathology, Diagnostic X-ray, Dialysis, Hearing Services, IV Therapy, Organ

Here In-Network: (Other than Tier 2 & 3 some extra words appear what here we use?

Hi @Vicky_K

How about this

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=\ssubject\sto\s).*?(?= copay)").Tostring

image

Alternative solution @Vicky_K

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=In-Network: \(Other than Tier 2 & 3).*?(\$\d+)").Groups(1)

image

Regards
gokul

2 Likes

@Vicky_K
Try this

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=\(Other than Tier 2 & 3.*)\W\d+\W\d+(?=\scopay)").Tostring

1 Like
System.Text.RegularExpressions.Regex.Matches(YourString,"(?<=\(Other than Tier 2 & 3.*)\W\d+\W\d+(?=\scopay)")(0).Tostring    to get 1 st $300

System.Text.RegularExpressions.Regex.Matches(YourString,"(?<=\(Other than Tier 2 & 3.*)\W\d+\W\d+(?=\scopay)")(1).Tostring  to get second  $300
1 Like

Hi Gokul,
I face some space, or some data increased in key word as below how can handle in regex,

In-Network (Other than Tier 2 & Tier 3): $200.00 copay

In-Network: (Other than Tier 2 & 3) - subject to $300.00 copay

In-network (Otherthan tier2&3) :$800.00

in-Network: (otherthantier2&3)- copay $900.00

These i get some of the different customer i need to get only amount

@Vicky_K
Does each line get from different Customers?
Like
Customer1–> In-Network (Other than Tier 2 & Tier 3): $200.00 copay

Customer2–> In-Network: (Other than Tier 2 & 3) - subject to $300.00 copay

Customer3–> In-network (Otherthan tier2&3) :$800.00

Customer4–>in-Network: (otherthantier2&3)- copay $900.00

@Vicky_K
If yes, use this

System.Text.RegularExpressions.Regex.Match(YourString,"\W\d+.\d+").Tostring.trim

You are genius can you help me to learn regex i have some question

System.Text.RegularExpressions.Regex.Match(YourString,“(?<=In-Network: (Other than Tier 2 & 3).*?($\d+)”).Groups(1)

($\d+) just explain me about this expression

Hi @Gokul_Jayakumar ,
Can you please tell me Regex expression above my reply??..

@Vicky_K Kindly create a new topic or send me a private message. Because this will create more junk confused who looking for the same issue.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.