示例#1
0
 def test_matchPatternsRotateTelephoneReturnsTrue(self):
     string = "7-917-293-191"
     reg = Regex(string)
     actual = reg.matchPatterns(pattern=r"917")
     patternX = re.compile(r'917')
     expected = []
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     self.assertEqual(actual, expected)
示例#2
0
 def test_findPatternOfDigitmatchPatternsTelephoneReturnsTrue(self):
     string = "7-917-293-191"
     reg = Regex(string)
     actual = reg.matchPatterns(pattern=r"\d")
     patternX = re.compile(r'\d')
     expected = []
     #Using \d searches for all characters that is between 0 - 9
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     self.assertEqual(actual, expected)
示例#3
0
 def test_findPatternOfDotmatchPatternsWebsiteReturnsTrue(self):
     string = "www.amandaplease.com"
     reg = Regex(string)
     actual = reg.matchPatterns(pattern=r"\.")
     patternX = re.compile(r'\.')
     expected = []
     #Backslash for metacharacters are need due to regex . ^ $ * + ? { } [ ] \ | ( )
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     self.assertEqual(actual, expected)
示例#4
0
 def test_matchPatternsAlphabetreturnsTrue(self):
     string = "abcAbcABCNYCBCAabc"
     reg = Regex(string)
     actual = reg.matchPatterns()
     patternX = re.compile(r'abc')
     expected = []
     for match in patternX.finditer(string):
         #match.start() = starting position of pattern
         expected.append(match.start())
         #match.group() = returns result of the first instance of match
         expected.append(match.group())
     self.assertEqual(actual, expected)
示例#5
0
 def test_BlockStringEntermatchPatternReturnsPositionAndInstanceOfMatch(
         self):
     string = """7-917-293-1191
     917"""
     reg = Regex(string)
     actual = reg.matchPatterns(pattern=r"917")
     patternX = re.compile(r'917')
     expected = []
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     self.assertEqual(actual, expected)
示例#6
0
 def test_findPatternOfwordExpressionmatchPatternsWebsiteReturnsTrue(self):
     string = "www.amandaplease.com"
     reg = Regex(string)
     regexExpression = r"\w"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     # \w returns a-z A-Z 0-9 _
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
示例#7
0
 def test_matchPatternsLikeAtEndReturnsNothing(self):
     string = """I said I like it like that"""
     reg = Regex(string)
     regexExpression = r"like$"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     # $ end of a string
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
示例#8
0
 def test_findPatternOfNotWordExpressionMatchPatternsWebsite(self):
     string = "www.amandaplease.com"
     reg = Regex(string)
     regexExpression = r"\W"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     # \W  returns not a-z A-Z 0-9 _ there should only return .
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
示例#9
0
 def test_findPatternOfDotExpressionmatchPatternsWebsiteReturnsTrue(self):
     string = "www.amandaplease.com"
     reg = Regex(string)
     regexExpression = r"."
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     # . return all characters that are not a new line
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
示例#10
0
 def test_matchPatternstelephoneEndReturnsAllInstance(self):
     string = """917-293-9422
     514*264*8577"""
     reg = Regex(string)
     regexExpression = r"\d\d\d.\d\d\d.\d\d\d\d"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     # /d - for digits - . all instance of word
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
示例#11
0
 def test_quantifierMatchPatternsReturnsTelephoneString(self):
     string = """917-293-9422
     514*264*8577"""
     reg = Regex(string)
     regexExpression = r"\d{3}[-*]\d{3}[-*]\d{4}"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     # /d - for digits {number} - exact number of matching patter
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
示例#12
0
    def test_findPatternOfNotWhiteSpaceExpressionMatchPatternsString(self):
        string = """I said I like it like that

        """
        reg = Regex(string)
        regexExpression = r"\S"
        actual = reg.matchPatterns(pattern=regexExpression)
        patternX = re.compile(regexExpression)
        expected = []
        # \s - return whitespac(space,tab, and newline)
        for match in patternX.finditer(string):
            expected.append(match.start())
            expected.append(match.group())
        print(actual)
        self.assertEqual(actual, expected)
示例#13
0
    def test_findPatternOfBoundaryExpressionMatchPatternsString(self):
        string = """I said I like it like that

        """
        reg = Regex(string)
        regexExpression = r"\bsaid\b"
        actual = reg.matchPatterns(pattern=regexExpression)
        patternX = re.compile(regexExpression)
        expected = []
        # \b - return boundary between words
        for match in patternX.finditer(string):
            expected.append(match.start())
            expected.append(match.group())
        print(actual)
        self.assertEqual(actual, expected)
示例#14
0
    def test_findPatternOfStartofStringMatchPatternsString(self):
        string = """I said I like it like that

        """
        reg = Regex(string)
        regexExpression = r"^I"
        actual = reg.matchPatterns(pattern=regexExpression)
        patternX = re.compile(regexExpression)
        expected = []
        # ^ start of a string
        for match in patternX.finditer(string):
            expected.append(match.start())
            expected.append(match.group())
        print(actual)
        self.assertEqual(actual, expected)
示例#15
0
    def test_findPatternOfWordBoundaryExpressionMatchPatternsHA(self):
        string = """Ha HaHa

        """
        reg = Regex(string)
        regexExpression = r"\bHa"
        actual = reg.matchPatterns(pattern=regexExpression)
        patternX = re.compile(regexExpression)
        expected = []
        # \b - return  word boundary
        # match the begin with boundary than ha
        for match in patternX.finditer(string):
            expected.append(match.start())
            expected.append(match.group())
        print(actual)
        self.assertEqual(actual, expected)
示例#16
0
 def test_MatchPatternsReturnEmails(self):
     string = """
     [email protected]
     [email protected]
     [email protected]
     [email protected]"""
     reg = Regex(string)
     regexExpression = r"[a-zA-Z0-9.\-_]+@[\w-]+\.(com|gov|net)+"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     #() group conditions together for matches that are option to match
     #[] sets of characters to look for
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
示例#17
0
 def test_MatchPatternsReturnsPrefixNamesString(self):
     string = """Mr Roy roger
     Mr. John Wayne
     mr Ray Yaz
     mr. Niz Hanif
     Ms Mary Jane Watson
     Ms Fanny Reguieg
     Ms Vanessa Ragubar"""
     reg = Regex(string)
     regexExpression = r"[mM]r\.?"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     # ? option value for the period if it is there or not return match
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
示例#18
0
 def test_matchPatternsNegateFNameReturnsNotFanny(self):
     string = """
        Raymond Mustafa
        Ryan Lion
        Khan Jr
        Nizmo
        Fanny
        """
     reg = Regex(string)
     regexExpression = r"[^F][a-z][a-z][a-z][a-z]"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     # ^  negate what you are not looking for in this case F
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
示例#19
0
 def test_matchPatternsNameReturnsFanny(self):
     string = """
        Raymond Mustafa
        Ryan Lion
        Khan Jr
        Nizmo
        Fanny
        """
     reg = Regex(string)
     regexExpression = r"[F][a-z][a-z][a-z][a-z]"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     #  looks for F and any letter after it
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
示例#20
0
 def test_SetSelectormatchPatternstelephoneEndReturnsAllInstance(self):
     string = """
     917-293-9422
     514*264*8577
     516a524a7485
     516452487485
     """
     reg = Regex(string)
     regexExpression = r"\d\d\d[-*]\d\d\d[-*]\d\d\d\d"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     # /d - for digits
     # . all instance of word
     # [-*] set selector looking for only instances of - and * in that one char
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
示例#21
0
 def test_MatchPatternsReturnURLsSocieteGeneralLowerrCaseURLs(self):
     string = """
     http://www.cartoonnetwork.com
     http://www.nick.com
     https://www.SocGen.net
     https://www.youtube.gov
     https://www.youtube.uk
     https://youtube.uk
     http://www.amandaplease.com
     http://www.amanda-please.com
     https://www.Ilovenum123.com"""
     reg = Regex(string)
     regexExpression = r"https?://(w{3}\.)?([socgen]+)(\.[a-zA-Z]+)"
     actual = reg.matchPatterns(pattern=regexExpression, flag=re.IGNORECASE)
     patternX = re.compile(regexExpression, flags=re.IGNORECASE)
     expected = []
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
示例#22
0
 def test_PeriodIsNotTheBestOptmatchPatternstelephoneEndReturnsAllInstance(
         self):
     string = """
     917-293-9422
     514*264*8577
     516a524a7485
     516452487485
     """
     reg = Regex(string)
     regexExpression = r"\d\d\d.\d\d\d.\d\d\d\d"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     # /d - for digits
     # . all instance of word
     # period is not the best instance because it returns also alphaNumeric instance
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
示例#23
0
 def test_MatchPatternsReturnFemaleNames(self):
     string = """Mr Roy roger
     Mr. John Wayne
     mr Ray Yaz
     mr. Niz Hanif
     Ms Rebecca Wong
     Ms Fanny Reguieg
     Ms Vanessa Ragubar"""
     reg = Regex(string)
     regexExpression = r"[mM]s\.?\s[A-Z]\w*\s\w*"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     # ? option value for the period if it is there or not return match
     # * return 0 or more instance of character matching
     # \s return space instance
     # \. period character
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
示例#24
0
 def test_MatchPatternsReturnURLs(self):
     string = """
     http://www.cartoonnetwork.com
     http://www.nick.com
     https://www.SocGen.net
     https://www.youtube.gov
     https://www.youtube.uk
     https://youtube.uk
     http://www.amandaplease.com
     http://www.amanda-please.com
     https://www.Ilovenum123.com"""
     reg = Regex(string)
     regexExpression = r"https?://(w{3}\.)?([a-zA-Z0-9/-]+)(\.[a-zA-Z]+)"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     #() group conditions together for matches that are option to match
     #[] sets of characters to look for
     #? match only if it exist or not for that char
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)