Newbie dot Org HomePage
Visit one of our web buddies
Regular Expressions
Sample / Examples
Return to main thread

#!/usr/bin/perl

use strict;

my ($tmpstring) = 'Newbie';

if ($tmpstring =~ /Newbie/) {
        print "\$tmpstring has Newbie in it\n";
} else {
        print "\$tmpstring does not have Newbie in it\n";
}

if ($tmpstring =~ /newbie/) {
        print "\$tmpstring has newbie in it\n";
} else {
        print "\$tmpstring does not have newbie in it\n";
}

exit;

Results:

$tmpstring has Newbie in it
$tmpstring does not have newbie in it


Return to main thread

A little extra

#!/usr/bin/perl

use strict;

my ($tmpstring) = 'Newbie';

if ($tmpstring =~ /Newbie/i) {
        print "\$tmpstring matches Newbie with (i)gnore case option\n";
}

if ($tmpstring =~ /newbie/i) {
        print "\$tmpstring matches newbie with (i)gnore case option\n";
}

print "\nSee what happens if dollar sign does not have slash in front\n";
print "$tmpstring matches newbie with (i)gnore case option\n";

exit;

Results:

$tmpstring matches Newbie with (i)gnore case option
$tmpstring matches newbie with (i)gnore case option

See what happens if dollar sign does not have slash in front
Newbie matches newbie with (i)gnore case option



Return to main thread