Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how extract the alphanumeric value using regex

import re
text  = """THE PO NUMBER 134314 MUST BE INCLUDED ALONG WITH
SERVICE DATE ON ALL INVOICES SUBMITTED THROUGH THE AVID BILL PAY PROCESS.
THANK YOU."""

p_no = re.search("PO# (\w+)|PO NUMBER (\w+)", text)
print(p_no)
if p_no == None:
    print("No value found")
else:
    print(p_no.group(1))

REQUIRED SOLUTION : 134314

Is there any solution to get the text after PO number but it should also take alphanumeric like B14786,AC7823 etc

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can put PO# and PO NUMBER in an alternation pattern in a non-capturing group so that there’s only one capturing group to deal with and that p_no.group(1) will always contain a value no matter which of PO# and PO NUMBER matches:

p_no = re.search(r"(?:PO#|PO NUMBER) (\w+)", text)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading