Whittle it on down

Random832 random832 at fastmail.com
Thu May 5 14:52:05 EDT 2016


On Thu, May 5, 2016, at 14:03, Steven D'Aprano wrote:
> You failed to anchor the string at the beginning and end of the string,
> an easy mistake to make, but that's the point.

I don't think anchoring is properly a concern of the regex itself -
.match is anchored implicitly at the beginning, and one could easily
imagine an API that implicitly anchors at the end - or you can simply
check that the match length == the string length.

> - Data validity doesn't matter, because there's no possible way that you
> might accidentally scrape data from the wrong part of a HTML file and end
> up with junk input.

If you've scraped data from the wrong part of the file, then nothing you
do to your regex can prevent the junk input from coincidentally matching
the input format.



More information about the Python-list mailing list