Sergio Spina wrote: > I know about greedy and not-greedy, but the problem remains.
This makes me wonder why you had to ask >>> Why the regex engine stops the search at last piece of string? >>> Why not at the first match of the group "@:"? To make it crystal clear this time: >>> import re >>> >>> patt = r""" # the match pattern is: ... .+? # one or more characters ... [ ] # followed by a space ... (?=[@#D]:) # that is followed by one of the ... # chars "@#D" and a colon ":" ... """ >>> pattern = re.compile(patt, re.VERBOSE) >>> m = pattern.match("Jun@i Bun#i @:Janji D:Banji #:Junji") >>> m.group() 'Jun@i Bun#i ' That's exactly what you asked for in >>> What can it be a regex pattern with the following result? >>> >>>> In [1]: m = pattern.match("Jun@i Bun#i @:Janji D:Banji #:Junji") >>>> >>>> In [2]: m.group() >>>> Out[2]: 'Jun@i Bun#i ' -- https://mail.python.org/mailman/listinfo/python-list