Need Help To Design REGEX For A Given Text/String

Hi,

I have been working for a complex project, for that a regex extraction is required. For some of regular expression, I have designed. But for others am struggling.

I need support to design the REGEX for strings am struggling for, strings are listed below.

  1. Total nett amount: CZK 4,305.52

Here I need regex to capture the amount

  1. Weight (gross / nett): 48.50 / 48.50 KG

here I need the regex to capture the both weights.

Your help will be appreciated.

Thanks & Regards,
Baruna K Panda

Hi @Panda_Baruna_K

System.Text.Regularexpressions.Regex.Match(yourString,"(?<=CZK\s)(\S+)").tostring

image

Regards
Gokul

Hey @Panda_Baruna_K,

you can use \d.+\d

Thanks,
Sanjit

@Panda_Baruna_K

System.Text.Regularexpressions.Regex.Match(yourString,"(?<=gross\s\/\snett\):\s).*(?=KG)").tostring

image

Regards
Gokul

Hi Gokul,

The problem with the expression is, “CZK” you have taken reference is dynamic value, so it will change for other data. Only “Total nett amount:” is constant.

Thanks,
Baruna K Panda

@Panda_Baruna_K

System.Text.Regularexpressions.Regex.Match(yourString,"\d.*").tostring

image

Hi Gokul,

It is capturing though, but it is capturing both at one go. I need to capture one by one, both are separate values & also dynamic in nature.

Thanks
Baruna K Panda

Hi @Panda_Baruna_K

System.Text.Regularexpressions.Regex.Match(yourString,"\d.*(?=KG)|\d.*").tostring

image

Regards
Gokul

Hi Sanjit,

the expression is matching for multiple values in the string, can we capture the “Total net amount:” string only.

Thanks
Baruna K Pada

Hi @Panda_Baruna_K

System.Text.RegularExpressions.Regex.Match("Total nett amount: CZK 4,305.52","(?<=amount:\s)\D+(\d.*)").Groups(1)

Regards
Gokul

1 Like

Hey @Panda_Baruna_K,

You can use look after method to get the desired result.
(?<=Total net amount:\s)\d.+\d

Thanks,
Sanjit

1 Like

I have found another way to capture that.

i.e (?<=Total nett amount: [A-Z]{3}\s)[\d,.]+

Thanks Sanjit for all your support.

1 Like

Hi Gokul,

Thanks for sharing it, I have found a an expression to capture that.

i.e (?<=Total nett amount: [A-Z]{3}\s)[\d,.]+

I appreciate your help.

Thanks.

1 Like

Hey @Panda_Baruna_K

The above regex is not working?

Hi Gokul,

It is working for me.

This expression is not working ? @Panda_Baruna_K

1 Like

I think this is better, the solution it was chosen i doesn’t work for me either

1 Like

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