A
A
Andrey Ovchinnikov2019-10-21 17:37:41
Java
Andrey Ovchinnikov, 2019-10-21 17:37:41

Regex searching for matches from the end of a string?

Good evening (day (night (morning))). The question arose, is it possible to start a Regex search from the end of a string, and not from the beginning?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2020-04-29
@sergeyibragimov

import re

text = "my name is vasya"

end_word = re.compile(r"(vasya)$")

if end_word.findall(text)[-1] == "vasya":
print(end_word.findall(text)[-1])

something like this?!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question