For a test.txt I used:#!/usr/bin/perl #get start and end comment my $start = $ARGV[0]; my $end = $ARGV[1] || "\n"; open(FILE, "test.txt") || die; { local $/ = undef; #set to 'slurp' mode $_ = <FILE>; #read entire file into $_ } close FILE; # #print all comments that are matched in file # while( /\Q$start\E(.*?)\Q$end\E/sg ) { print $&, "\n"; }
For my execution results I got (my exe is called regex.pl):blah blah blah blah blah *** multi line comment **!! blah blah blah blah blah blah blah blah blah blah blah *** inline comment **!! blah blah /* c comment 1 */ blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah /* * c comment 2 */ blah blah // c++ comment 1 blah blah // c++ comment 2
prompt$ regex.pl '***' '**!!' *** multi line comment **!! *** inline comment **!! prompt$ regex.pl '/*' '*/' /* c comment 1 */ /* * c comment 2 */ prompt$ regex.pl '//' // c++ comment 1 // c++ comment 2
In reply to Re: matching comments
by perlmonkey
in thread matching comments
by Eugene
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |