Я не могу пройти этот вызов кода:
Задача поиска регулярного выражения с использованием строки Python ниже для
выполнить поиск с помощью созданного вами регулярного выражения.
search_string = ’’ ’Это строка для поиска регулярного выражения
как регулярное выражение или регулярное выражение или регулярное: выражение или
регулярное выражение &»»»
Напишите регулярное выражение, которое найдет все вхождения: a.
регулярное выражение б. регулярное выражение c. регулярный: выражение d.
регулярное & выражение в строке поиска
Присвойте регулярное выражение переменной с именем pattern
Используя метод findall () из пакета re, определите, есть ли
вхождения в строке поиска
Назначить результат метода findall () переменной с именем match1
Если match1 не является None: a. Распечатайте на консоли шаблон, используемый для
выполнить совпадение, за которым следует слово «совпал»
В противном случае: а. Распечатайте на консоль шаблон, используемый для выполнения
совпадение, за которым следуют слова «не совпадают»
Вот мой код:
import re
#The string to search for the regular expression occurrence (This is provided to the student)
search_string = '''This is a string to search for a regular expression like regular expression or
regular-expression or regular:expression or regular&expression'''
#1. Write a regular expression that will find all occurrences of:
# a. regular expression
# b. regular-expression
# c. regular:expression
# d. regular&expression
# in search_string
#2. Assign the regular expression to a variable named pattern
ex1 = re.search('regular expression', search_string)
ex2 = re.search('regular-expression', search_string)
ex3 = re.search('regular:expression', search_string)
ex4 = re.search('regular&expression', search_string)
pattern = ex1 + ex2 + ex3 + ex4
#1. Using the findall() method from the re package determine if there are occurrences in search_string
#. Assign the outcome of the findall() method to a variable called match1
#2. If match1 is not None:
# a. Print to the console the pattern used to perform the match, followed by the word 'matched'
#3. Otherwise:
# a. Print to the console the pattern used to perform the match, followed by the words 'did not match'
match1 = re.findall(pattern, search_string)
if match1 != None:
print(pattern + 'matched')
else:
print(pattern + 'did not match')
Я не получаю никаких отзывов от программы. Это просто говорит мне, что я потерпел неудачу без сообщения об ошибке.