🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.perl
Article #1207

Re: /\+(?:\(.*?\)|.*?)(?:$|(?=\+))/g

#1207
From: Qrczak
Date: Fri, 10 Apr 1998 20:41
42 lines
2321 bytes
On Fri, 10 Apr 1998, Michal Mosiewicz wrote:

> Natomiast przyznam, że wyrażenie .*? mógłbyś spokojnie zastąpić
> następującym wyrażeniem:
[...]

man perlre:

       By default, a quantified subpattern is "greedy", that is,
       it will match as many times as possible (given a
       particular starting location) while still allowing the
       rest of the pattern to match.  If you want it to match the
       minimum number of times possible, follow the quantifier
       with a "?".  Note that the meanings don't change, just the
       "greediness":

           *?     Match 0 or more times
           +?     Match 1 or more times
           ??     Match 0 or 1 time
           {n}?   Match exactly n times
           {n,}?  Match at least n times
           {n,m}? Match at least n but not more than m times

BTW: Nawet gdyby to nie miało specjalnego znaczenia, to .*? byłoby
równoważne .*, a nie napisowi pustemu.

Moje pytanie sprowadza się do tego: Czy jeśli przy czymś takim:
  ( wyr1 | wyr2 )
w danym miejscu pasują oba wyrażenia, to zostanie użyte wyr1, czy też
z góry nie wiadomo?

Argument za tym, żeby z tego skorzystać: Upraszcza to konkretny problem;
w praktyce nie zaobserwowałem, żeby to nie zadziałało w ten sposób.

Argument przeciwny: Być może nie musi tak zadziałać - wtedy po prostu
_trzeba_ pomęczyć się nie korzystając z tego.

-- 
                                 QRCZAK
    __("<              Marcin Kowalczyk
    \__/              qrczak@knm.org.pl
     ^^      http://qrczak.home.ml.org/
Technical Details
Message-ID: <Pine.LNX.3.96.980410223424.10137B-100000@qrnik.knm.org.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!news.icm.edu.pl!news.task.gda.pl!qrnik.knm.org.pl!qrnik.knm.org.pl!qrczak
References: <Pine.LNX.3.96.980410093444.16675A-100000@qrnik.knm.org.pl> <352E6572.BAFC5F3@interdata.com.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!news.icm.edu.pl!news.task.gda.pl!qrnik.knm.org.pl!qrnik.knm.org.pl!qrczak
From: Qrczak <qrczak@knm.org.pl>
Newsgroups: pl.comp.lang.perl
Subject: Re: /\+(?:\(.*?\)|.*?)(?:$|(?=\+))/g
Date: Fri, 10 Apr 1998 22:41:38 +0200
Organization: Klub Nieszkodliwych Manjaków
Lines: 43
Message-ID: <Pine.LNX.3.96.980410223424.10137B-100000@qrnik.knm.org.pl>
References: <Pine.LNX.3.96.980410093444.16675A-100000@qrnik.knm.org.pl> <352E6572.BAFC5F3@interdata.com.pl>
NNTP-Posting-Host: ppp4-105.warszawa.tpnet.pl
Mime-Version: 1.0
In-Reply-To: <352E6572.BAFC5F3@interdata.com.pl>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit