正则表达式前视和/或后视错误
$line = 'bob never never said every reverie is good';
查找:仅匹配并捕获单词“ever”。使用前瞻和/或后瞻断言来执行此操作。
if ( $line =~ /(?<=\s)ever(?=\s)/) {
print "matched ";
}
替换:使用您想要的任何机制从行中删除单词“ever”及其后面的空格。
$line =~ s/ever\s+//;
print $line ;
Extra-Credit:使用您想要的任何机制将字符偏移量获取到单词“ever”的字符串中。
my $result = index($line,'ever');
print $result;
我已经写了考试。但我不是穿越者。这些答案有什么问题?
$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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)