Need help with Regex!

I need help with the regex pattern for the below string to extract the amount along with the currency symbol highlighted below. The word before the currency symbol can vary, in this case it is Cost but it will vary case to case, but the word Out of Pocket is constant across all the cases.

Cost £ 341,072 Out of Pocket

Regexp pattern I used is : \S\s\S+(?=\s+Out\sof\sPocket) but I think it is not reliable so can anyone suggest a better expression for this to work?

Thank you!

Hi,

How about the following expression?

System.Text.RegularExpressions.Regex.Match(strData,"£\s*[,\d]+(?=\s+Out\sof\sPocket)").Value

Regards,

1 Like

This is works, thank you for your quick reply. But the currency symbol varies too, it can be pounds, dollars or anything else, sorry I did not mention it earlier. Thanks for your help.

Hi,

But the currency symbol varies too, it can be pounds, dollars or anything else,

Can you try the following?

System.Text.RegularExpressions.Regex.Match(strData,"\p{Sc}\s*[,\d]+(?=\s+Out\sof\sPocket)").Value

Regards,

2 Likes

Brilliant @Yoichi !! This works perfectly.

1 Like

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