Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #108379

Re: Help for a complex RE

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: Help for a complex RE
Date Sun, 08 May 2016 20:19:31 +0200
Organization None
Lines 33
Message-ID <mailman.527.1462731580.32212.python-list@python.org> (permalink)
References <2aa55bd8-2ea4-41f7-b188-d45dff7d3bb7@googlegroups.com> <ngnomu$n3i$1@ger.gmane.org> <mailman.520.1462724202.32212.python-list@python.org> <6a3fe5cd-0ba9-4017-a763-76c896b8c843@googlegroups.com> <ngnvvl$1pp$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Trace news.uni-berlin.de xLqdB7AB3cq5l7QmlTd4WwPz1HV4anxJGFNHj/novpvA==
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '"""': 0.05; 'stops': 0.07; '[1]:': 0.09; '[2]:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Help': 0.10; '":"': 0.16; 'r"""': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'import': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.26; 'followed': 0.27; 'wonder': 0.27; 'time:': 0.27; 'colon': 0.29; 'asked': 0.29; 'problem': 0.33; 'clear': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'why': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'space': 0.40; 'engine': 0.62; 'more': 0.63; 'sergio': 0.84; 'greedy': 0.91
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host p57bd8cd3.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <ngnvvl$1pp$1@ger.gmane.org>
X-Mailman-Original-References <2aa55bd8-2ea4-41f7-b188-d45dff7d3bb7@googlegroups.com> <ngnomu$n3i$1@ger.gmane.org> <mailman.520.1462724202.32212.python-list@python.org> <6a3fe5cd-0ba9-4017-a763-76c896b8c843@googlegroups.com>
Xref csiph.com comp.lang.python:108379

Show key headers only | View raw


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 '

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


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