Govind Bhone
Govind Bhone

Reputation: 13

Escaping white spaces in nestedExpr pyparsing

import pyparsing as pp
print(pp.nestedExpr(opener="(", closer=")").parseString("(account={eq:T 1 No Lim})", parseAll=True)[0])

Above code gives me below output:

['account={eq:T', '1', 'No', 'Lim}']

But I want to escape white spaces from value part and want below output:

[u'account={eq:T 1 No Lim}']

Can anyone please suggest ?

Upvotes: 1

Views: 169

Answers (2)

Govind Bhone
Govind Bhone

Reputation: 13

[u'account={eq:T1NoLim}'] is the output when i used "(account={eq:T1NoLim})" in example string But when i used "(account={eq:T 1 No Lim})" then getting below output ['account={eq:T', '1', 'No', 'Lim}']

Upvotes: 0

Tenzin
Tenzin

Reputation: 2505

Maybe you can make use of originalTextFor.

For example:

import pyparsing as pp
print(pp.originalTextFor(pp.nestedExpr(opener="(", closer=")")).parseString("(account={eq:T 1 No Lim})", parseAll=True)[0])

Upvotes: 1

Related Questions