Skip to content

Instantly share code, notes, and snippets.

@AndrewRussellHayes
Created November 20, 2013 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewRussellHayes/7570441 to your computer and use it in GitHub Desktop.
Save AndrewRussellHayes/7570441 to your computer and use it in GitHub Desktop.
perl string matching with tail anchor
#!/usr/bin/perl
use strict;
use warnings;
# if the string ends in z regardless of case the below returns true
my $string = '"abcdefz"';
my $string2 = "abcefj";
my $last;
$last = substr($string,-2,1);
print $last;
if ($last =~ /Z/i)
{
print "yay";
}
else
{
print "noooo";
}
if ($string2 =~ /Z$/i)
{
print "yay";
}
else
{
print "noooo";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment