描述
此匹配運算符用於匹配給定表達式中的任何關鍵字。首字母 m 後的括號可以是任何字符,將用於分隔正則表達式語句。
正則表達式變量包括 $,它包含最後匹配的分組; $&,包含整個匹配的字符串; $`,包含匹配字符串之前的所有內容;和 $',它包含匹配字符串之後的所有內容。
用法
以下是此函數的簡單語法 âˆ'
m//
返回值
此函數在失敗時返回 0,成功時返回 1,
示例
以下是顯示其基本用法的示例代碼 -
#!/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
相關用法
- Perl map用法及代碼示例
- Perl my用法及代碼示例
- Perl sin()用法及代碼示例
- Perl abs()用法及代碼示例
- Perl kill用法及代碼示例
- Perl chop()用法及代碼示例
- Perl wantarray用法及代碼示例
- Perl gmtime用法及代碼示例
- Perl exists()用法及代碼示例
- Perl split用法及代碼示例
- Perl localtime用法及代碼示例
- Perl delete()用法及代碼示例
- Perl undef用法及代碼示例
- Perl reset()用法及代碼示例
注:本文由純淨天空篩選整理自 Perl m Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。