String splitting in Python using regex
Question: I'm trying to split a string in Python so that I get everything before a
certain regex.

example string: `"Some.File.Num10.example.txt"`

I need everything before this part: `"Num10"`, regex: `r'Num\d\d'` (the number
will vary and possibly what comes after).

Any ideas on how to do this?


Answer: 
    >>> import re
    >>> s = "Some.File.Num10.example.txt"
    >>> p = re.compile("Num\d{2}")
    >>> match = p.search(s)
    >>> s[:match.start()]
    'Some.File.'
    

This would be more efficient that doing a split because search doesn't have to
scan the whole string. It breaks on the first match. In your example it
wouldn't make a different as the strings are short but in case your string is
very long and you know that the match is going to be in the beginning, then
this approach would be faster.

I just wrote a small program to profile search() and split() and confirmed the
above assertion.

