Pattern for Amount

Hi Guys,

I am creating a pattern to match amounts like USD 20000, INR 500 ,EUR 20, GBP 100 etc. with some other currencies followed by some amount. Please see my pattern below:

pattern = [{'ORTH': 'USD', 'OP': '?'},
           {'ORTH': 'EUR', 'OP': '?'},
           {'ORTH': 'GBP', 'OP': '?'},
           {'IS_DIGIT': True}] 

I am due to add more currencies but for now just trying with USD, EUR and GBP.
Issue with this pattern is that it will match digits that are not lead by any currency. e.g 1000
Do i need to create separate pattern for each currency type or there is any way to mention that at least one of the the given currency should match in above expression?

Thanks in advance.

If you haven't seen it already, you might find the pattern explorer demo useful that lets you test your patterns against example texts:

Also check out the rule-based matching documentation and the extended pattern syntax that'd also let you write "ORTH": {"IN": ["USD", "EUR", "GBP"]}. When writing patterns, I'd focus on readability and maintainability. Sometimes it's better to split the logic into several patterns than trying to cram everything into one with complex logic (and potentially making them harder to read and debug).