[Linuxtrent] regexp

  • From: Luca Manini <manini@xxxxxxxxxxx>
  • To: Linux Trent <linuxtrent@xxxxxxxxxxxxx>
  • Date: Thu, 27 Jun 2002 12:05:34 +0200

Problema: di regexp ce ne sono N tipi, dopo trovo una spiegazione
"chiara" delle differenze?

Ho già guardato le man pages (o info) di ed, sed, awk e soci (mi manca
perl); ma ciascuno fa un bel casino a spiegare le proprie, alcuni
parlano di BRE (base regular expressions) e ERE (extended ...) senza
però chiarire molto le cose; poi come al solito ci si mette POSIX.

Ad esempio, l'info di (GNU) ed, verso al fine dice:

        The following extended operators are preceded by a backslash
        `\' to distinguish them from traditional `ed' syntax.

Ma poi di dire quale fosse la predetta sintassi...


        Qualcuno ha un link a qualche fonte di "acqua pura"?




PS E poi se ne scopre sempre una, della serie "strano ma vero":

`*'
     Matches the single character regular expression or subexpression
     immediately preceding it zero or more times.  If `*' is the first
     character of a regular expression or subexpression, then it matches
     itself.  The `*' operator sometimes yields unexpected results.  For
     example, the regular expression `b*' matches the beginning of the
     string `abbb', as opposed to the substring `bbb', since a null
     match is the only left-most match.

ed in effetti:

calvin:~> echo 'abbb' | sed 's/b*/_/'
_abbb
calvin:~> echo 'abbb' | sed 's/b\+/_/'
a_
calvin:~>

Vale quindi il detto (cito memoria): 

        Alcuni programmatori, quando hanno UN problema pensano, 
        
                "Adesso scrivo una bella regexp"

        Adesso hanno DUE problemi.
-- 
Per iscriversi  (o disiscriversi), basta spedire un  messaggio con SOGGETTO
"subscribe" (o "unsubscribe") a mailto:linuxtrent-request@xxxxxxxxxxxxx


Other related posts: