Perl——正则表达式(三) 更多匹配 //g

前端之家收集整理的这篇文章主要介绍了Perl——正则表达式(三) 更多匹配 //g前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一. 介绍

//g 会执行匹配多次

二. 实例

$x = "cat dog house"; # 3 words
while ($x =~ /(\w+)/g) { # \w 匹配单词字符:[a-zA-Z_0-9] ; + 表示1次或多次
	print "Word is $1,ends at position ",pos $x,"\n";
	# 结果
	# Word is cat,ends at position 3
	# Word is dog,ends at position 7
	# Word is house,ends at position 13
}

猜你在找的Perl相关文章