javascript – Regex retrieve digits after specific words

I have a google app script that parses some pdfs and I started with the following regex, that retrieves the 5 sets of 3digits from Reference tag:

[w,W,s,S]*(\d{3}).?(\d{3}).?(\d{3}).?(\d{3}).?(\d{3})

I added to it more versatility to also retrieve 9 digits combination for Reference tag;

[w,W,s,S]*(\d{3}).?(\d{3}).?(\d{3}).?(\d{3})?.?(\d{3})?

Both versions only match the digits, no words, which is perfect.

I would like to also retrieve the digits related to Amount tag, while ignoring any words and digits in between. And it’s here that I’m having some trouble.

I tried:

.*?(?:Ref)(?:.*:) ? ?(\d{3}).?(\d{3}).?(\d{3}).?(\d{3})?.?(\d{3})?

But it already starts to include the word.

This is some dummy text example of the text where the regex is being used:

  • can have more words after each “tag” (example: Reference of something // Amount of first payment🙂

  • can have : or not

    Some dummy text that may have words in common like `reference` or `amount` throughout the document
    
    Reference: 245 154 343 345 345
    Entity: 34567    
    Amount: 11,11
    Payment date: 14/07/2022
    
    Some more text
    

Thank you in advance for any help.

Read more here: Source link