Previous

Next


26. Perl Options - Free form regexes

  • Yay for Perl! You can use "/x" to make your regexes much simpler to read by adding comments to them! Don't forget to escape your spaces and literal "#"'s though, as free-form Perl regexes allows these for formatting and starting comments:
      #!/usr/bin/perl
      $_ = "How about this for a target!";
      if (m/
            (       # Start capturing $1
              this  #  Match "this"
              |     # OR
              for   #  match "for"
            )       # End capture for $1
             /x) {
        print "$1\n";
      }
    
    gives:
      this
    

Previous

Next

Andrew Hill

For LinuxSA Meeting, 17 April 2001