This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import re | |
def count_substrings_re( string, substring ): | |
substring_re = '(?=(%s))' % re.escape( substring ) | |
return len( re.findall( substring_re, string ) ) | |
def count_substrings_re_opt(string, substring): | |
if len( substring )==1: | |
substring_re = re.escape( substring ) |