Tuesday, October 16, 2012

Perl regular expression match

Simple Test Perl Script to test perl match

#!/usr/bin/perl

if ($ARGV[0] =~ m/.*ORA-0*(54|1142|1146|1234)(\D.*|$)/ ) {
print "match \n" ;
} else {
print "no match \n";
}

print "$ARGV[0] \n";

TEST:
[test@test shell]$ perl test.pl 'idfsdfsd ORA-1234'
match
idfsdfsd ORA-1234
[test@test shell]$ perl test.pl 'idfsdfsd ORA-123'
no match
idfsdfsd ORA-123
[test@test shell]$ perl test.pl 'idfsdfsd ORA-1234 ss'
match
idfsdfsd ORA-1234 ss
[test@test shell]$ perl test.pl 'idfsdfsd ORA-1234:'
match
idfsdfsd ORA-1234:
[test@test shell]$ perl test.pl 'idfsdfsd ORA-124:'
no match
idfsdfsd ORA-124:
[test@test shell]$ perl test.pl 'idfsdfsd OR-1234:'
no match
idfsdfsd OR-1234:
[test@test shell]$

Wild Character:
. - any character
.* - 0 or any repeated cahracter
a* - 0 or any repeated a
( a|b|c) - a or b or c
$ - end of sring
\D - none digit charactor
[0-9] -digit charactor
[^0-9] - none digit charactor

Reference:

No comments:

Post a Comment