Activity 12.13.1.
Modify the ### to find sequences with one uppercase letter followed by an underscore followed by one or more lowercase letters.
Solution.
# Line 1: import re
# Line 3: [A-Z] matches uppercase letter characters and [a-z] matches lowercase letter characters
# Line 4: Use the pattern variable to search the text
# Line 6: Include the else statement
import re
def text_match(text):
pattern = '[A-Z]_[a-z]+'
if re.search(pattern, text):
return('Found a match!')
else:
return('Not matched!')
print(text_match("aab_cbbbc"))
====
from unittest.gui import TestCaseGui
class MyTests(TestCaseGui):
def testOne(self):
self.assertEqual(text_match("aab_cbbc"), "Not matched!", 'text_match("aab_cbbc")')
self.assertEqual(text_match("aaA_bbbc"), "Found a match!", 'text_match("aaA_bbbc")')
self.assertEqual(text_match("A_abbbc"), "Found a match!", 'text_match("A_abbbc")')
self.assertEqual(text_match("word_A"), "Not matched!", 'text_match("word_A")')
self.assertEqual(text_match("myZ_oo"), "Found a match!", 'text_match("myZ_oo")')
MyTests().main()

