开发者

PHP regex:Find all 6 digit numbers in a string that do not end in 00

开发者 https://www.devze.com 2022-12-31 19:35 出处:网络
I\'m trying to find all the 6 digit numbers in a string that do not end in 00. Something like that /([0-9]{4})([^00])///i know this is wrong

I'm trying to find all the 6 digit numbers in a string that do not end in 00. Something like that /([0-9]{4})([^00])/ //i know this is wrong

so the string

asdfs dfg_123456_adsagu432100jhasj654321

will give me

results=[123456,6开发者_运维技巧54321] and not 432100

Thanks

Have a good day


Use negative lookbehind: \d{6}(?<!00)

See also

  • regular-expressions.info/Lookarounds


You're misusing the character class.
Just like [ab] matches a orb, [00] matches 0 or 0. A single character class cannot match two characters at once.
[^00] matches a single non-zero character (such as a)

Instead, use the following:

/([0-9]{4})([0-9][1-9]|[1-9][0-9])/
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号