in reply to Regexing a block of text in between patterns
use strict; use warnings; my $text = "C:\\letters.txt"; my @letters; open IN, '<', $text or die "Can't open $text"; @letters = <IN>; close(IN); chomp @letters; foreach my $indiv_note (@letters) { if ($indiv_note =~ /\[Sidenote\:\s(.*?)\]/) { print "<div>$1</div>\n"; } }
Note that the way I have written this, sidenotes cannot cross line boundaries, though doing this would be fairly trivial. Also note that if you want to include [ and ] in your posts, you should use html entities, i.e. [ and ]
|
|---|