# Write code to split a string at uppercase letters # using regular expression, # and print them as string # Example, a string "IWillDoMorePractice" # will result in "I Will Do More Practice" import re text = "IWillDoMorePractice" regex = re.compile(r'([A-Z])([^A-Z]*)') # I Will result = "" matches = regex.finditer(text) for match in matches: print(match, match.group(), match.group(0), match.group(1), match.group(2)) # matches = regex.findall(text) # for match in matches: # # print(match) # result += match + " " # # print(result) # findall() returns the occurrences of the pattern in the target string # - create a list of occurrences of a pattern in a string # - group(), start(), end() not applicable # search() gives more information than just the actual patterns # - tell where the pattern occurs in the target string # - returns a match object for the first occurrence # - returns None if pattern is not found # match() checks if the pattern exists at the very *start* of a string # - returns None if pattern not found # note: Python processes None as False # finditer() creates a list (or an iterator) of match objects for where # the pattern occurs in a string # - thus, can iterate a list of match objects and use group(), start(), end()