I want to match a string with the following criteria:
- Match any letters, followed by a '.', followed by letters, followed by end-of-line.
For example, for the string 'www.stackoverflow.com', the regex should return 'stackoverflow.com'. I have the following code that works:
my_string = '''
123.domain.com
123.456.domain.com
domain.com
'''
>>> for i in my_string.split():
... re.findall('[A-Za-z\.]*?([A-Za-z]+\.[a-z]+)$', i)
...
['domain.com']
['domain.com']
['domain.com']
>>>
The code snippet above works perfectly. But I'm sure there must be a more elegant way to achieve the same.
Is it possible to start the regex search/match starting from the end of the string, moving towards the start of the string? How would one code that type of regex? Or should I be using regex at all?
iandmmodifiers: poc.