我在编写Perl程序以提取某个单词之后的单词时遇到困难。
例如:
Today i'm not going anywhere except to office.
我想要之后这个词anywhere
,所以输出应该是except
。
我已经试过了
my $words = "Today i'm not going anywhere except to office.";
my $w_after = ( $words =~ /anywhere (\S+)/ );
但这似乎是错误的。
很接近:
my ($w_after) = ($words =~ /anywhere\s+(\S+)/);
^ ^ ^^^
+--------+ |
Note 1 Note 2
注意1:=~
返回已捕获项目的列表,因此分配目标必须是列表。
注2:之后允许一个或多个空格 anywhere
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句