-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperl_regex1.pl
executable file
·59 lines (44 loc) · 1 KB
/
perl_regex1.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/perl -w
#
# Module: perl_regex1.pl
# Purpose: This module demonstrates some Perl regular expressions
# Author: Wade Hampton
# Date: 10/27/2015
# Notes:
# 1) TBD
#
use warnings;
use strict;
my $s = "This is a very\ long! stringish string with lots, lots, lots of stuff!.!*(&(";
print "perl_regex1.pl: simple regex in Perl\n";
print "Input=" . $s . "\n";
my $s_test = "lot";
print "Does it contain ". $s_test ."?\n";
if ($s =~ /$s_test/) {
print "YES\n";
}
print "Testing using the default variable \$_\n";
$_ = $s;
if (/$s_test/) {
print "Also found \"$s_test\" in \$_\n";
}
$s_test = "junk";
print "Testing \"$s_test\" ";
if (/$s_test/) {
print "Found\n";
} else {
print "Nope, not found\n";
}
print "Testing for not matching \"$s_test\" ";
if ($s !~ /$s_test/) {
print "Not found\n";
} else {
print "Found\n";
}
$s_test = "^This";
print "Testing matching string at start using ^\n";
if ($s =~ /$s_test/) {
print "Found\n";
} else {
print "Not found\n";
}