Bry*_*nry 1 regex perl alternation
有人可以解释为什么我的匹配表现不同,无论交替是否包含在捕获组中?
这可能是由于Perl的旧版本(遗憾的是我无法控制),还是我误解了什么?我的理解是,括号是某些人的约定,但在这种情况下则不必要.
[~]$ perl -v
This is perl, v5.6.1 built for PA-RISC1.1-thread-multi
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2001, Larry Wall
Binary build 633 provided by ActiveState Corp. http://www.ActiveState.com
Built 12:17:09 Jun 24 2002
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.
[~]$ perl -e 'print "match\n" if ("getnew" =~ /^get|put|remove$/);'
match
[~]$ perl -e 'print "match\n" if ("getnew" =~ /^(get|put|remove)$/);'
[~]$
Run Code Online (Sandbox Code Playgroud)
^get|put|remove$
发现^get
或put
或remove$
.因此,"getnew"匹配模式,因为它始于get
.
而^(get|put|remove)$
发现^get$
或^put$
或^remove$
.
归档时间: |
|
查看次数: |
81 次 |
最近记录: |