הלינקייה: מגזין חודשי למפתחים

רוצה לשמוע על כל האירועים, המדריכים, הקורסים והמאמרים שנכתבו החודש ?
הלינקייה הינו מגזין חופשי בעברית שמשאיר אותך בעניינים.
בלי ספאם. בלי שטויות. פעם בחודש אצלך בתיבה.

Basic Regular Expressions

    Regular Expressions Symbols

    Assertions Quantifiers Metacharacters
    \A, ^ - true at the begining of a string * match zero or more times [] Any character inside the []
    \Z, $ - true at the end of a string + match 1 or more times ...|... alterations
    \G true at the end-of-match position of prior m//g ? match 1 or 0 times \s match whitespace
    \b true at word boundary {COUNT} match exactly COUNT times \w match a word character
    {MIN, MAX} match at least MIN times but not more than MAX times \d match a digit character
    . match any character
    use strict;
    use warnings;
    
    my $has_a_number = qr {
    # this regular expression matches a string
    # that has at least one digit somewhere ...
        \d    [ ]   \d
    }xms;
    
    my $starts_with_http = qr {
    # matches any string that starts with http://
    # very useful for interneting
    
    # we start the line
        ^
    # then look for the http (and maybe the https)
    
        https?
    
    # finish with a :// 
        ://
    
    }xms;
    
    warn 'matching against: ', $has_a_number;
    
    while (my $line = <>) {
        print "Kaboom !\n" if $line =~ $has_a_number;
    }
    
    while (my $line = <>) {
        print "Kaboom !\n" if $line =~ /\d/;
    }
    
    while (<>) {
        print "Kaboom !\n" if /^http:\/\//;
    }
    
    use strict;
    use warnings;
    
    my $DOUBLE_SPACES_RE = qr {
    # catch any number of whitespaces and tabs
        [ \t]+
    }xms;
    
    while (<>) {
        s/$DOUBLE_SPACES_RE/ /g;
        print;
    }
    
    
    use strict;
    use warnings;
    
    my $IDENTIFIER_RE = qr {
        \b
    # take some text
        (   [a-zA-Z_]+  )
    # which ends with one or more digits
    
        (   \d+    )
    
        \b
    }xms;
    
    my $TWO_WORDS = qr {
        (\b\w+\b)
    
        \s+
    
        (\b\w+\b)
    
    }xms;
    
    while (my $line = <>) {
        my ($word, $count) = $line =~ m/$IDENTIFIER_RE/;
        
        next if ! $count;
    
        print $word x $count, "\n";
    }
    
    while (my $line = <>) {
        $line =~ s/$TWO_WORDS/$2 $1/g;
        print $line;
    }
    
    
    use strict;
    use warnings;
    
    my $DUPS_RE = qr {
        
        (\b\w+\b)
    
        .*
    
        \1
    
    }xms;
    
    while (<>) {
        my ($dup) = m/$DUPS_RE/;
        next unless $dup;
    
        warn "the word $dup is duplicated !";
    }
    
    
    course: