# File regexFile.pl # Regular expressions(regex). String =~ /Pattern/ same as String =~ m/Pattern/ # Match (m) the String with Pattern # Last succesful match. System variables take values: # $` = first part $& = fit $' = last part # Test if matching takes place #$line = 'VERSION 1. This is a test line from a text file.'; $line = ' 23. VERSION 1. This is a test line from a text file.'; # Check start word if ($line =~ /^VERSION/i) # i stands for IGNORE case {print "Line= $line \n starts with word VERSION\n"}; if ($line =~ /^[0-9]/) {print "Line= $line \n starts with a digit\n"}; if ($line =~ /^[\s0-9]/) {print "Line= $line \n with space or digit\n"}; if ($line =~ /^[\sVERSION]/) {print "Line= $line \n starts space or word VERSION\n"}; $line =~ m/a\s/ ; print "first= ",$`, "\n fit= ", $&, "\n last= ", $'; # Line= 23. VERSION 1. This is a test line from a text file. # first= 23. VERSION 1. This is # fit= a # last= test line from a text file. # line is a end of record line: \\/n or m!//n! # $line =~ //\/\/\n/ ; #?? to test exit;