Need To Extract Purchase order number starts with 9000

Hi Team,

can you please help how to extract purchase order number from below sentence it starts with “900”

string value:
(INVOICE
This address is for Invoice Number “Purchase Order No.”
PO Box 1870 return mail only. 26929147 “900020982”
Ashland VA 23005-4870 Payments should be
sent to address on Ordered by: DARIN PHIPPS
coupon below. Sub-Total: 32.58
Shipping, Handling
Customer Number: 02156508 & Surcharge: 0.00
Sales Tax: 0.00
Total: $32.58
06973 06973
ORIGINAL PACKING SLIP #: 2692914

Bill To: ICON METAL FORMING LLC
ATTN: ACCOUNTS PAYABLE Ship To: ICON METAL FORMING LLC
2190 LANDMARK AVE NE 2190 LANDMARK AVE NE)

Regards,
Manoj.

Hi @manojmanu.rpa ,

Maybe you can try using the below regex :

(?<=""Purchase Order No.""[\S\s]+)9000\d+

Expression :

Regex.Match(yourInputStrVar,"(?<=""Purchase Order No.""[\S\s]+)9000\d+").Value.Trim

Also, do confirm if the Purchase Order No. will always start from 9000.

Hello @manojmanu.rpa
Try Regex Expression

System.text.regularexpressions.regex.match(YourStr,"(?=900)\d+").tostring.trim

Hi @supermanPunch

Thanks
incase if number was not start with 900 how can we get the purchase order number .,Please help.

Regards,
Manoj.

Hi @manojmanu.rpa

Option 1:

Updating the pattern from @supermanPunch - you can use the below to match exactly 9 numbers in a row with no reliance on “900”. Regex Preview link

System.Text.RegularExpressions.Regex.Match(yourInputStrVar,“(?<=Purchase Order No.[\S\s]+)\d{9}”).Value.Trim

Option 2:
I have a second pattern which might suit your needs.

The pattern relies on:

  • If the purchase order number is always 9 digits long then this will work Including the ‘900’
  • Has only 0 or 1 non-digits at the end.

Regex Pattern - Preview the pattern here
System.Text.RegularExpressions.Regex.Match(yourInputStrVar,“\d{9}(?=\D?[\r\n])”).Value.Trim

Option 3:

The pattern relies on:

  • Matching any number of digits which appear at then of a line.
  • Has only 0 or 1 non-digits at the end.

System.Text.RegularExpressions.Regex.Match(yourInputStrVar,“\d+(?=\D?[\r\n])”).Value.Trim

Hopefully this helps :blush:

Thnaks @Steven_McKeering :clap:

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