S
Steven Bethard
Within a larger pyparsing grammar, I have something that looks like::
wsj/00/wsj_0003.mrg
When parsing this, I'd like to keep around both the full string, and the
AAA_NNNN substring of it, so I'd like something like::
(['wsj/00/wsj_0003.mrg', 'wsj_0003'], {})
How do I go about this? I was using something like::
... '.mrg')
But of course then all I get back is the full path::
(['wsj/00/wsj_0003.mrg'], {})
I could leave off the final Combine and add a parse action::
... wsj_name = tokens[4]
... return ''.join(tokens), wsj_name
... ([('wsj/00/wsj_0003.mrg', 'wsj_0003')], {})
But that then allows whitespace between the pieces of the path, which
there shouldn't be::
([('wsj/00/wsj_0003.mrg', 'wsj_0003')], {})
How do I make sure no whitespace intervenes, and still have access to
the sub-expression?
Thanks,
STeVe
wsj/00/wsj_0003.mrg
When parsing this, I'd like to keep around both the full string, and the
AAA_NNNN substring of it, so I'd like something like::
(['wsj/00/wsj_0003.mrg', 'wsj_0003'], {})
How do I go about this? I was using something like::
... '.mrg')
But of course then all I get back is the full path::
(['wsj/00/wsj_0003.mrg'], {})
I could leave off the final Combine and add a parse action::
... wsj_name = tokens[4]
... return ''.join(tokens), wsj_name
... ([('wsj/00/wsj_0003.mrg', 'wsj_0003')], {})
But that then allows whitespace between the pieces of the path, which
there shouldn't be::
([('wsj/00/wsj_0003.mrg', 'wsj_0003')], {})
How do I make sure no whitespace intervenes, and still have access to
the sub-expression?
Thanks,
STeVe