diff options
author | Paul McGuire <ptmcg@austin.rr.com> | 2012-10-02 04:55:56 +0000 |
---|---|---|
committer | Paul McGuire <ptmcg@austin.rr.com> | 2012-10-02 04:55:56 +0000 |
commit | a7f9dda0668bfce4fba51df1bf2976b4a93a8bd5 (patch) | |
tree | 57ea8bcf2e66532a36c833a7bc57cff9d5d0e4dd /src/examples/parseResultsSumExample.py | |
parent | f5d2b716ffb57b65660a7ee0bbf04332dfb29620 (diff) | |
download | pyparsing-git-a7f9dda0668bfce4fba51df1bf2976b4a93a8bd5.tar.gz |
Add example files to SVN
Diffstat (limited to 'src/examples/parseResultsSumExample.py')
-rw-r--r-- | src/examples/parseResultsSumExample.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/examples/parseResultsSumExample.py b/src/examples/parseResultsSumExample.py new file mode 100644 index 0000000..6da5e84 --- /dev/null +++ b/src/examples/parseResultsSumExample.py @@ -0,0 +1,26 @@ +#
+# parseResultsSumExample.py
+#
+# Sample script showing the value in merging ParseResults retrieved by searchString,
+# using Python's builtin sum() method
+#
+samplestr1 = "garbage;DOB 10-10-2010;more garbage\nID PARI12345678;more garbage"
+samplestr2 = "garbage;ID PARI12345678;more garbage\nDOB 10-10-2010;more garbage"
+samplestr3 = "garbage;DOB 10-10-2010"
+samplestr4 = "garbage;ID PARI12345678;more garbage- I am cool"
+
+from pyparsing import *
+dob_ref = "DOB" + Regex(r"\d{2}-\d{2}-\d{4}")("dob")
+id_ref = "ID" + Word(alphanums,exact=12)("id")
+info_ref = "-" + restOfLine("info")
+
+person_data = dob_ref | id_ref | info_ref
+
+for test in (samplestr1,samplestr2,samplestr3,samplestr4,):
+ person = sum(person_data.searchString(test))
+ print person.id
+ print person.dump()
+ print
+
+
+
\ No newline at end of file |