Help for a complex RE
Peter Otten
__peter__ at web.de
Sun May 8 14:19:31 EDT 2016
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 at i Bun#i @:Janji D:Banji #:Junji")
>>> m.group()
'Jun at 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 at i Bun#i @:Janji D:Banji #:Junji")
>>>>
>>>> In [2]: m.group()
>>>> Out[2]: 'Jun at i Bun#i '
More information about the Python-list
mailing list