parseResultsSumExample.py 815 B

1234567891011121314151617181920212223
  1. #
  2. # parseResultsSumExample.py
  3. #
  4. # Sample script showing the value in merging ParseResults retrieved by searchString,
  5. # using Python's builtin sum() method
  6. #
  7. samplestr1 = "garbage;DOB 10-10-2010;more garbage\nID PARI12345678;more garbage"
  8. samplestr2 = "garbage;ID PARI12345678;more garbage\nDOB 10-10-2010;more garbage"
  9. samplestr3 = "garbage;DOB 10-10-2010"
  10. samplestr4 = "garbage;ID PARI12345678;more garbage- I am cool"
  11. from pyparsing import *
  12. dob_ref = "DOB" + Regex(r"\d{2}-\d{2}-\d{4}")("dob")
  13. id_ref = "ID" + Word(alphanums,exact=12)("id")
  14. info_ref = "-" + restOfLine("info")
  15. person_data = dob_ref | id_ref | info_ref
  16. for test in (samplestr1,samplestr2,samplestr3,samplestr4,):
  17. person = sum(person_data.searchString(test))
  18. print(person.id)
  19. print(person.dump())
  20. print()