此匹配运算符用于匹配给定表达式中的任何关键字。起始m后面的括号可以是任何字符,将用于分隔正则表达式语句。
Regular expression variables include $, which contains whatever the last grouping match matched; $&, which contains the entire matched string; $`, which contains everything before the matched string; and $', which contains everything after the matched string.
以下是此函数的简单语法-
m//
如果失败,此函数返回0,如果成功,则返回1,
以下是显示其基本用法的示例代码-
链接:https://www.learnfk.comhttps://www.learnfk.com/perl/perl-m.html
来源:LearnFk无涯教程网
#!/usr/bin/perl -w $string="The food is in the salad bar"; $string =~ m/foo/; print "Before: $`\n"; print "Matched: $&\n"; print "After: $'\n";
执行上述代码后,将产生以下输出-
Before: The Matched: foo After: d is in the salad bar
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
PPT设计进阶 · 从基础操作到高级创意 -〔李金宝(Bobbie)〕