topical media & game development

talk show tell print

basic-regex-26-PositionalMetacharacters.pl / pl



  #!/usr/bin/perl -w
  use strict;
  print "\nThis example demonstrates the use of the ^ and $ positional metacharacters.\n\n";
  my myPattern = "cape";
  my myTestString = "escape";
  print "In 'myTestString' there is a match for the pattern 'myPattern'.\n\n" if (myTestString =~ m/myPattern/);
  
  myPattern = "^cape";
  print "When the pattern is 'myPattern' there is no match for 'myTestString'.\n\n" if (myTestString !~ m/myPattern/);
  myPattern = "cape$";
  print "But there is a match for 'myTestString' when the pattern is 'myPattern'.\n\n" if (myTestString =~ m/myPattern/);


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.