use strict;
my $str = '你先唱给我听好吗
快唱啊
快唱啊你
你唱吧
你唱一个
唱一首吧亲爱的
再唱一首
你快唱吧
你能唱出来吗
唱出来
唱一个给我听呗好不好
快唱
唱
唱吧
你唱啊
唱一个嘛
唱一个啊
来听你唱歌
再给我唱一首呗
唱歌小万
你唱首歌给我听呗
陪我一起唱歌好吗
听你唱歌这么难
唱首歌来听听
你唱歌好好听啊再给我唱一首呗
我现在就很不开心你唱首歌给我听呗
会不会唱歌,唱首歌来听听';
my $regex = qr/^.{0,1}(陪我一起)?听?你?(再|快|先)?能?(给我)?唱?(啊|一?个|吧|出来|一?首)?歌?(给我听|来听听)?(吧|啊|哇|呗|呀)?((好(么|嘛|吗))|好不好|小万|亲爱的|这么难)?.{0,1}$/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html