Marinus
Marinus

Reputation: 2210

How do you parse a literal asterisk with pyparsing?

I'm currently parsing a string, which can contain wildcards. My grammar only works, if you put the asterisk in quotes. How do you specify a literal *.

selection = QuotedString('"') | Word(printables) | Literal('*') 

Upvotes: 2

Views: 566

Answers (1)

PaulMcG
PaulMcG

Reputation: 63749

Any literal '*' is going to get sucked up into a Word(printables). Do you mean to have the word be made up of any printables that aren't asterisks? If so, then you can just change to:

selection = QuotedString('"') | Word(printables, excludeChars='*') | Literal('*') 

Upvotes: 1

Related Questions