[Dresden-pm] Frage zu einem regulären Ausdruck

Renée Bäcker mailinglisten at renee-baecker.de
Sa Jan 23 04:06:28 PST 2010


Bei mir hat sich eben ein kleiner Fehler eingeschlichen. Natürlich 
landet das äußere () in $3. Aber für den inneren Ausdruck wird nichts in 
$4 gespeichert. Sorry für die Ungenauigkeit.


Nachtrag: Für solche Fragen ist das Modul YAPE::Regex::Explain einfach 
genial. Für diesen RegEx erklärt das Modul folgendes:

(?-imsx:^a2(en|dis)(mod|site)((?:-.+)?)$)

matches as follows:

NODE                     EXPLANATION
----------------------------------------------------------------------
(?-imsx:                 group, but do not capture (case-sensitive)
                         (with ^ and $ matching normally) (with . not
                         matching \n) (matching whitespace and #
                         normally):
----------------------------------------------------------------------
  ^                        the beginning of the string
----------------------------------------------------------------------
  a2                       'a2'
----------------------------------------------------------------------
  (                        group and capture to \1:
----------------------------------------------------------------------
    en                       'en'
----------------------------------------------------------------------
   |                        OR
----------------------------------------------------------------------
    dis                      'dis'
----------------------------------------------------------------------
  )                        end of \1
----------------------------------------------------------------------
  (                        group and capture to \2:
----------------------------------------------------------------------
    mod                      'mod'
----------------------------------------------------------------------
   |                        OR
----------------------------------------------------------------------
    site                     'site'
----------------------------------------------------------------------
  )                        end of \2
----------------------------------------------------------------------
  (                        group and capture to \3:
----------------------------------------------------------------------
    (?:                      group, but do not capture (optional
                             (matching the most amount possible)):
----------------------------------------------------------------------
      -                        '-'
----------------------------------------------------------------------
      .+                       any character except \n (1 or more
                               times (matching the most amount
                               possible))
----------------------------------------------------------------------
    )?                       end of grouping
----------------------------------------------------------------------
  )                        end of \3
----------------------------------------------------------------------
  $                        before an optional \n, and the end of the
                           string
----------------------------------------------------------------------
)                        end of grouping
----------------------------------------------------------------------




Die Verwendung von ?: kann auch sinnvoll sein, wenn man Speicher und 
Laufzeit sparen will...

- Renée

-- 
Perl-Magazin: http://perl-magazin.de
Perl-Nachrichten: http://perl-nachrichten.de




Mehr Informationen über die Mailingliste Dresden-pm