#! /usr/bin/perl use strict; use utf8; #1 符号:$& $` $‘ my $str="my name is hello world,and her name is hello world"; if($str=~m/name/g){ print $`,"\n";#匹配到的字符串的前面部分 print $‘,"\n";#匹配到字符串的后面部分 print $&,"\n";#匹配到的字符串 } #result: my is hello world,and her name is hello world name
时间: 2024-10-10 12:05:03