Mike Coleman <mkc at mathdogs.com> writes: > If you've ever been frustrated that there wasn't an easy way to parse a string > or file, even though you could easily match it with re.match, then this PEP > may be for you. If what's being proposed seems a little ghastly, well, I'll > just say that I've been wanting something like this for a long time and this > is the best I could come up with. Your comments invited. Generally, it strikes me as mildly useful. An implementation would surely help :-) Presumably 'structmatch' would also become a metho on pattern objects? > Additional Features > ------------------- > > In many cases in which ``'re.structmatch'`` fails to match, the cause will > be due to an unexpected error in the format of the string being > matched. In order to assist the calling program in generating a more > meaningful possible error message, ``'re.structmatch'`` will return the > endpoint of the largest match against the searched string. So, for > example :: > > re.structmatch('abcd', 'abxxx') --> 2 > re.structmatch('abcde|z', 'abxxx') --> 2 > re.structmatch('x*?y', 'xxx') --> 3 > > (This return value should be considered advisory rather than exact, as > future improvements in the match algorithm may make it difficult to > calculate the exact value.) I don't really like this idea; it seems to be that it would be more helpful to raise an exception and attach this data to the exception. But that's a bit inconsisent with how match and search work. Cheers, mwh -- I have a cat, so I know that when she digs her very sharp claws into my chest or stomach it's really a sign of affection, but I don't see any reason for programming languages to show affection with pain. -- Erik Naggum, comp.lang.lisp
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4