微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

正则表达式 – 为什么`stoutest`不是有效的正则表达式?

perlop开始:

If “/” is the delimiter then the initial m is optional. With the m you can use any pair of non-whitespace characters as delimiters. This is particularly useful for matching path names that contain “/”,to avoid LTS (leaning toothpick syndrome). If “?” is the delimiter,then the match-only-once rule of ?PATTERN? applies. If “‘” is the delimiter,no interpolation is performed on the PATTERN. When using a character valid in an identifier,whitespace is required after the m.

所以我可以把任何一封信作为分隔符.最终这个正则表达式应该没问题:

stoutest

那可以改写

s/ou/es/

但它似乎在Perl中不起作用.为什么?

$perl -e '$_ = qw/ou/; stoutest; print'
ou
因为Perl无法挑选出操作符

perldoc perlop说这个

Any non-whitespace delimiter may replace the slashes. Add space after the s when using a character allowed in identifiers.

这个程序工作正常

my $s = 'bout';
$s =~ s toutest;
say $s;

产量

best

原文地址:https://www.jb51.cc/regex/356744.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐