parse logo parse: compile

1 2 3 4 5
Notes

If you're going to be running the same format string over many inputs it will make sense to compile the format first. This makes the code cleaner, but it may also cause a performance boost.

from parse import compile

p = compile("https://github.com/{account}/{project}/")

txt = "https://github.com/koaning/scikit-lego/"
p.parse(txt)

txt = "foo https://github.com/koaning/scikit-lego/"
p.search(txt)

txt = "https://github.com/koaning/scikit-lego/ https://github.com/koaning/scikit-lego/"
p.findall(txt)

Important

In this series of videos we've been exploring parse by using it to parse urls. If you're really only dealing with URLs you may want to explore yarl. It's a tool that's specialized to that task. The goal of parse is to be a general tool for strings in python. Not just URLs.

Much in the same fashion, if you're dealing with dates you'll likely want to check out datefinder.