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 ";
}