php9跟09的区别,php – [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(默认为默认模式)时可视化差异.查看默认值是如何反转的.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值