php – [0-9]和[0-9]之间有什么区别?

栏目: PHP · 发布时间: 7年前

内容简介:有人可以解释一下[0-9]和[0-9]之间的区别是什么?翻译自:https://stackoverflow.com/questions/6186569/what-is-the-difference-between-0-9-and-0-9

有人可以解释一下[0-9]和[0-9]之间的区别是什么?

PHP用于正则表达式的PCRE引擎支持 “possessive quantifiers”

Quantifiers followed by + are “possessive”. They eat as many characters as possible and don’t return to match the rest of the pattern. Thus .*abc matches "aabc" but .*+abc doesn’t because .*+ eats the whole string. Possessive quantifiers can be used to speed up processing.

和:

If the 07001 option is set (an option which is not available in Perl) then the quantifiers are not greedy by default, but individual ones can be made greedy by following them with a question mark. In other words, it inverts the default behaviour. 

不同之处在于:

/[0-9]+/  - one or more digits; greediness defined by the PCRE_UNGREEDY option
/[0-9]+?/ - one or more digits, but as few as possible (non-greedy)
/[0-9]++/ - one or more digits, but as many as possible (greedy, default)

This snippet 在贪婪默认模式下可视化差异.请注意,第一个片段在功能上与最后一个片段相同,因为默认情况下已经应用了(在某种意义上)附加片段.

This snippet 在应用PCRE_UNGREEDY(默认为默认模式)时可视化差异.查看默认值是如何反转的.

翻译自:https://stackoverflow.com/questions/6186569/what-is-the-difference-between-0-9-and-0-9


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

世界是数字的

世界是数字的

[美] Brian W. Kernighan / 李松峰、徐建刚 / 人民邮电出版社 / 2013-6 / 49.00

家用电器、汽车、飞机、相机、手机、GPS 导航仪,还有游戏机,虽然你看不见,但这些设备都有计算能力。手机通信网络、有线电视网络、空中交通管制系统、电力系统、银行和金融服务系统等基础设施背后无一不是计算机在支撑。如今的世界是数字的,而计算机和计算无处不在。这本书就是要告诉大家数字世界有关计算机的一切。本书没有高深莫测的专业术语,但它全面解释了当今计算和通信领域的工作方式,包括硬件、软件、互联网、通信......一起来看看 《世界是数字的》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具