Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
use strict;
use warnings;
my $text = qq(This is the first line
and another
above me
the line below me is blank
end);
my $word = 'the';
while($text =~
/ #start regex
(?: #start group and don't remember it
\W|\A #non-word character \W or start of string \A
) #end group
( #start new group (and remember it)
$word #search for the special word
\W #followed by a non-word character
.*? #and a minimalist matching of zero or more of any chars
) #end group
\n\n #followed by a blank newline (two in a row)
/sgx #end regex and have modifiers
#s treats the string as one long string and not as separate lines
#it allows the . to match a newline
#g searches globally, so turn this off if you want only the first match
#x allows comments and ignores spacing, letting the regex span multiple lines
) #end while condition
{
print "Match: $1\n"; #$1 stores the match from $word to \n\n
}
# open OUT fh to output file
my $word = 'test'; #Define word here
while (<>) {
if (s/^.*?(\b$word\b)/$1/../^\s*$/) {
unless (/^\s*$/) {
$rec .= $_;
}
else {
print OUT $rec;
$rec = '';
}
}
}