, . , , -, .
1:
, , , , .
MARKDOWN_LINK_REGEX = re.compile(r'\[(.*?)\]\((.*?)\)')
, , , . , , .
2:
def uppercase_comment(comment):
result = comment.upper()
for match in re.finditer(MARKDOWN_LINK_REGEX, comment):
upper_match = match.group(0).upper()
corrected_link = upper_match.replace(match.group(2).upper(),
match.group(2))
result = result.replace(upper_match, corrected_link)
return result
-, , . , regex (re.finditer), , , , .
, - . (, , ), , , .
3: Out
if __name__ == '__main__':
print(uppercase_comment('this comment has zero links'))
print(uppercase_comment('this comment has [a link at the end](Google.com)'))
print(uppercase_comment('[there is a link](Google.com) at the beginning'))
print(uppercase_comment('there is [a link](Google.com) in the middle'))
print(uppercase_comment('there are [a few](Google.com) links [in](StackOverflow.com) this one'))
print(uppercase_comment("doesn't matter (it shouldn't!) if there are [extra parens](Google.com)"))
THIS COMMENT HAS ZERO LINKS
THIS COMMENT HAS [A LINK AT THE END](Google.com)
[THERE IS A LINK](Google.com) AT THE BEGINNING
THERE IS [A LINK](Google.com) IN THE MIDDLE
THERE ARE [A FEW](Google.com) LINKS [IN](StackOverflow.com) THIS ONE
DOESN'T MATTER (IT SHOULDN'T!) IF THERE ARE [EXTRA PARENS](Google.com)
. , Python 3, 3- , , - . ββ