Perl 中的 m函数

首页 / Perl入门教程 / Perl 中的 m函数

描述

此匹配运算符用于匹配给定表达式中的任何关键字。起始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

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

深入浅出gRPC -〔李林锋〕

面试现场 -〔白海飞〕

从0开始做增长 -〔刘津〕

大规模数据处理实战 -〔蔡元楠〕

Python核心技术与实战 -〔景霄〕

如何讲好一堂课 -〔薛雨〕

快速上手C++数据结构与算法 -〔王健伟〕

结构思考力 · 透过结构看问题解决 -〔李忠秋〕

PPT设计进阶 · 从基础操作到高级创意 -〔李金宝(Bobbie)〕

好记忆不如烂笔头。留下您的足迹吧 :)