Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #108363
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2016-05-08 08:18 -0700 |
| Message-ID | <2aa55bd8-2ea4-41f7-b188-d45dff7d3bb7@googlegroups.com> (permalink) |
| Subject | Help for a complex RE |
| From | Sergio Spina <sergio.am.spina@gmail.com> |
In the following ipython session:
> Python 3.5.1+ (default, Feb 24 2016, 11:28:57)
> Type "copyright", "credits" or "license" for more information.
>
> IPython 2.3.0 -- An enhanced Interactive Python.
>
> In [1]: import re
>
> In [2]: 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 ":"
> ...: """
>
> In [3]: pattern = re.compile(patt, re.VERBOSE)
>
> In [4]: m = pattern.match("Jun@i Bun#i @:Janji")
>
> In [5]: m.group()
> Out[5]: 'Jun@i Bun#i '
>
> In [6]: m = pattern.match("Jun@i Bun#i @:Janji D:Banji")
>
> In [7]: m.group()
> Out[7]: 'Jun@i Bun#i @:Janji '
>
> In [8]: m = pattern.match("Jun@i Bun#i @:Janji D:Banji #:Junji")
>
> In [9]: m.group()
> Out[9]: 'Jun@i Bun#i @:Janji D:Banji '
Why the regex engine stops the search at last piece of string?
Why not at the first match of the group "@:"?
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 '
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Help for a complex RE Sergio Spina <sergio.am.spina@gmail.com> - 2016-05-08 08:18 -0700
Re: Help for a complex RE Peter Otten <__peter__@web.de> - 2016-05-08 18:15 +0200
Re: Help for a complex RE Sergio Spina <sergio.am.spina@gmail.com> - 2016-05-08 09:32 -0700
Re: Help for a complex RE Terry Reedy <tjreedy@udel.edu> - 2016-05-08 13:17 -0400
Re: Help for a complex RE Peter Otten <__peter__@web.de> - 2016-05-08 20:19 +0200
csiph-web