-
Notifications
You must be signed in to change notification settings - Fork 2
/
regexptest.pl
executable file
·51 lines (44 loc) · 1.37 KB
/
regexptest.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
#!/usr/bin/perl
# test regular expressions
print "Please input a string to test against: ";
$input = <STDIN>;
chomp($input);
# .1.3.6.1.2.1.25.2
# period, one or more digits, repeated one or more times
# $input =~ s/^([.\d+]+)$/$1/g;
# print "substituted text is >$1<\n";
# HH:MM ???
#my $regex = '\d\d:\d\d \(\d+?\+?\d+:\d+\)';
# phone number
#my $regex = '\d{3}-\d{3}-\d{4}';
# MS-DOS path/filename
# ^([c-zC-Z]:/[a-zA-Z0-9_.-]+)
# a file path: >./deathmatch/deathtag:<
#my $regex = q(^\.[\/\w]*:$);
#if ( $input =~ m#^([c-zC-Z]:/[a-zA-Z0-9_.-]+)# ) {
#if ( $regex =~ s/^\s([a-zA-Z0-9\.,]+)\s+$/$1/g ) {
#my $regex = q(^[a-zA-Z]+$);
# regex for finding Rex tasks/batch tasks
# - multiline because of the '\x' modifier
my $regex = qr/
^task[ \t]* "([a-zA-Z0-9_]+)"\s{0,},
|^task[ \t]*q{1,2}\(([a-zA-Z0-9_-]+)\)\s{0,},
|^batch[ \t]*"([a-zA-Z0-9_-]+)"\s{0,},
|^batch[ \t]*q{1,2}\(([a-zA-Z0-9_-]+)\)\s{0,},
/x;
#my $regex = qr/^task[ \t]*q{1,2}\(([a-zA-Z0-9_-])\),/;
# for matching text...
if ( $input =~ $regex ) {
print qq(Worked!\n);
} else {
print qq(Did not work!\n);
} # if ( $input =~
# for substituting text...
#my $regex = qr/.*#(\d+);.*/;
#if ( $input =~ s/$regex/$1/ ) {
# print qq(Worked! \$input is now '$input' \n);
#} else {
# print qq(Did not work! \$input is still $input\n);
#} # if ( $input =~
print "regex: '$regex'\n";
print "input: '$input'\n";