Reputation: 35077
$line = 'bob never ever said every reverie was good';
Looking: Match and capture ONLY the word 'ever'. Do so using lookahead and/or lookbehind assertions.
if ( $line =~ /(?<=\s)ever(?=\s)/) {
print "matched ";
}
substituting: Remove the word 'ever' and the space after it from the line using any mechanism you'd like.
$line =~ s/ever\s+//;
print $line ;
Extra-Credit: Get the character offset into the string of the word 'ever' using any mechanism you'd like.
my $result = index($line,'ever');
print $result;
I have wrote the exam. but i am not passs through. What is wrong in these answers ?
Upvotes: 1
Views: 249
Reputation: 7392
Upvotes: 4