r1chardj0n3s / parse

Parse strings using a specification based on the Python format() syntax.
http://pypi.python.org/pypi/parse
MIT License
1.72k stars 101 forks source link

Consider adding Result.span #101

Open florisla opened 4 years ago

florisla commented 4 years ago

I would find it useful if I could query

result.span

Just like I can get the span tuple information of individual fields (result.spans['field']).

I realize "span" name-clashes a bit with the spans propery; perhaps it could be called full_span ?

Edit: the purpose is to make replacing text easier -- see #100.

the-admax commented 2 months ago

Since 1.8.2, it's possible to go the other way round:

for m in parse.findall(some_format, text, evaluate_result=False):  # Notice 'evaluate_result=False'
  m.match.span()  # <-- This provides access to re.Match.span field hence the whole match span
  m.evaluate_result()  # <-- This returns variables captured in format string