Skip to content

Instantly share code, notes, and snippets.

@hastebrot
Created May 6, 2014 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hastebrot/afcdae0935a13f460256 to your computer and use it in GitHub Desktop.
Save hastebrot/afcdae0935a13f460256 to your computer and use it in GitHub Desktop.
from pyparsing import *
def match(text, matcher):
result = matcher.parseString(text)
return result
if __name__ == "__main__":
element = Word(alphas)
matcher = ZeroOrMore(element + FollowedBy(element)) + Group(element)
print match("a b c d e f", matcher) # ['a', 'b', 'c', 'd', 'e', ['f']]
print match("a b c d e", matcher) # ['a', 'b', 'c', 'd', ['e']]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment