We need to be careful because the parse
function is very picky.
from parse import parse
# This will match just fine
parse("https://github.com/{account}/{project}/",
"https://github.com/koaning/scikit-lego/")
# This will match just fine but `project` will contain `/`
parse("https://github.com/{account}/{project}",
"https://github.com/koaning/scikit-lego/")
# This will return `None`
parse("https://github.com/{account}/{project}/",
"https://github.com/koaning/scikit-lego")
Another downside of parse
is that the string needs to match the
format string perfectly. That means that it won't be able to find
substrings that match either! If you'd like to do that, you need to
use the search
function instead.
from parse import parse, search
# This will return `None`
parse("https://github.com/{account}/{project}/",
"foo https://github.com/koaning/scikit-lego/")
# This will match just fine.
search("https://github.com/{account}/{project}/",
"foo https://github.com/koaning/scikit-lego/")