catch whether the regex is valid or not before we perform any operations

the problem was that we assumed validity and so setting .count resulted in an npe. if we simply create an empty MatchData, we run into issues later where we rely on len(matchData.indexes) > 0, which it will not be. we call ClearMatchData() at the beginning of all regex functions, so it seems OK to check out the regex here.