[Solved] Regex substring in python3


No need for regex here, you can just split the text on \n and : , i.e..:

text =  """It sent a notice of delivery of goods: UserName1
Sent a notice of delivery of the goods: User is not found, UserName2
It sent a notice of receipt of the goods: UserName1
It sent a notice of receipt of the goods: User is not found, UserName2"""

for x in text.split("\n"):
    print(x.split(": ")[1])

If you prefer a regex, and to avoid multiple : on the line, you can use:

for x in text.split("\n"):
    print(re.split(".*: ", x)[1])

Output:

UserName1
User is not found, UserName2
UserName1
User is not found, UserName2

2

solved Regex substring in python3