[Dresden-pm] Reguläre Ausdrücke - Suchen und Ersetzen von Worten

Thomas Rittsche thomas.rittsche at gmail.com
Di Aug 12 07:51:16 PDT 2008


Hallo Aristoteles, hallo Falk,
vielen Dank erst mal für Eure Hilfe. Ich muss wirklich erst mal
schauen, ob ich das nutzen kann, ohne dass die Performance leidet.

@Aristoteles: Wenn Langeweile in Kopenhagen aufkommt, würde ich mich
noch über ein paar Erläuterungen freuen.

Vielen Dank noch mal!

Thomas


2008/8/12 Aristotle Pagaltzis <pagaltzis at gmx.de>:
> * Falk Herrmann <falk.herrmann at bike24.net> [2008-08-12 10:35]:
>> Mal schauen, was noch kommt.
>
>    my @keywords = ( 'affe', 'hund', 'affe klettert', 'hund rennt' );
>    my $text = 'Ein Affe klettert, weil er ein Affe ist. Ein Hund rennt, weil er ein Hund ist.';
>
>    my %insertion;
>    for my $kw ( @keywords ) {
>        my ( $rx ) = map qr/$_/i, quotemeta $kw;
>        while ( $text =~ /$rx/g ) {
>            push    @{ $insertion{ $-[0] } }, '<a href="#">';
>            unshift @{ $insertion{ $+[0] } }, '</a>';
>        }
>    }
>
>    my $result    = '';
>    my $last_offs = 0;
>    for my $offset ( sort { $a <=> $b } keys %insertion ) {
>        $result
>            .= substr( $text, $last_offs, $offset - $last_offs )
>            .  join( '', @{ $insertion{ $offset } } );
>
>        $last_offs = $offset;
>    }
>
>    $result .= substr( $text, $last_offs );
>
> Ich habe leider keine Zeit, das zu erklären, weil mein Flug zur
> YAPC::EU gleich geht.
>
> --
> *AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1}
> &Just->another->Perl->hack;
> #Aristoteles Pagaltzis // <http://plasmasturm.org/>
> _______________________________________________
> Dresden-pm mailing list
> Dresden-pm at pm.org
> http://mail.pm.org/mailman/listinfo/dresden-pm
>


Mehr Informationen über die Mailingliste Dresden-pm