Skip to content

Instantly share code, notes, and snippets.

@ruicovelo
Last active January 3, 2016 05:29
Show Gist options
  • Save ruicovelo/8416652 to your computer and use it in GitHub Desktop.
Save ruicovelo/8416652 to your computer and use it in GitHub Desktop.
The simplest way I found to parse a string accepting words separated by <space> and grouping togetther words inside quotes. Does not support nested quotes... yet...
from pyparsing import printable,quotedString,Word,OneOrMore
#text = 'words out of quotes "words inside quotes" more words out "and more words in"'
frase=OneOrMore(Word(printable) | quotedString)
@ruicovelo
Copy link
Author

I was using Word(alphanums) but replaced alphanums with printable because quotedString accepts all kind of crap making Word(printable) a bit more close to what quotedString accepts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment