[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: RegEx Frage...



Gebhard Dettmar <gebhard.dettmar@student.hu-berlin.de> wrote:
>> uptime | perl -pe 's/^.*up (.*?,.*?),.*$/\1/'
> Versteh ich nicht. In dem RegEx Ausdruck lese ich 2 Quantifizierer
> hintereinander, * = keinmal, 1x, oder öfter und dann ? = kein- oder
> einmal. Wozu ist letzteres gut? Warum nicht einfach: (.+,.+)
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



	Christoph



Reply to: