读书人

perl正则表达式基础的有关问题

发布时间: 2012-03-19 22:03:05 作者: rapoo

perl正则表达式基础的问题
$_ = "Hello there,nerghbor ";
if (/(\w+),/) {
print "the word was $1\n ";
}

为什么$1=there 而不是Hello呢?

[解决办法]
因为还需要匹配后面的一个 ', ',改成如下即可:

$_ = "Hello there,nerghbor ";
if (/(\w+)/) {
print "the word was $1\n ";
}

读书人网 >perl python

热点推荐