The parse module is a useful as an inverse of format
. Its documentation mentions (referring to the format specification mini-language) that
The align operators will cause spaces (or specified fill character) to be stripped from the parsed value. The width is not enforced; it just indicates there may be whitespace or "0"s to strip.
I would like to do something like this, but I wasn't able to find any examples of how to get this to work. For example, in its normal operation, if I use a template "{}{}"
to match "ab"
, I get a Result
object which contains 'a'
and 'b'
:
In [1]: import parse
In [2]: parse.parse("{}{}","ab")
Out[2]: <Result ('a', 'b') {}>
However, if I put a space between a
and b
in the string, then that space alters the Result
:
In [3]: parse.parse("{}{}","a b")
Out[3]: <Result ('a', ' b') {}>
I would like the parse.parse
method to ignore this space and still return 'a'
and 'b'
. Is this possible and if so, how can I do it?