I am facing a challenge to match an amount and currency combination using regular expressions. It can be the Currency(3 capital letters) followed by Amount(numbers, commas and dots) or Amount followed by Currency.
Samples -
USD 1,000.00
99,766.76 EUR
Both of the above values should be matched. I am able to match both of them separately, but not using a single regex condition. Any help of this would be really helpful
Thanks @Yoichi , I am able to match both the formats. I actually have to split the text into currency and amount group in a single regex.
I had something like (?<CCY>\w{3})\s*(?<AMT>[0-9.,]*) to retrieve the currency and amount as a separate group. I don’t want to make too many changes to the script to implement this change. I am looking for a single regex condition that could get me the CCY and AMT for the above 2 examples.
Please note that only either one of the format will be available, i.e either USD 1,000.0 or 1,000.00 USD and not both. But the regex should be applicable for both the format
Thanks @Yoichi , This is very close to what I need. The problem is, I am not able to use the same group name for currency and amount for the 2 different formats. I had to use different group names for Currency (CCY and CCY2). Is there a possibility to have only one group name CCY and AMT to get the matches for the above 2 formats?
To put it straight, my regex condition should have only 2 group names CCY and AMT instead of 4 to match the Currency/Amount Format.
example of what I ideally need -
(?<CCY>[A-Z]{3}) (?<AMT>[\d.,]+)|(?<CCY>[\d.,]+) (?<AMT>[A-Z]{3})
But this will not work as the group names cannot be repeated in Regex conditions. Is there any conditional way to specify the group?
For example - if the next 3 are [A-Z] use group <CCY> or if the characters until the next space are [0-9.,], use group <AMT> ?
OMG! I apologize. I was so into the Regex101 that I didn’t give it a thought to try in Studio. The Regex101 gave me a pattern error and I thought Regex doesn’t allow duplicate pattern name -
Thanks again @Yoichi , I was frequently getting engine related errors when I was using that, so I switched to other options. But appreciate this note as it could be useful for others.