PHP regex: 00 bitmez bir dize 6 haneli numaraları

2 Cevap php

Hello all 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

böylece dize

asdfs dfg_123456_adsagu432100jhasj654321

Bana verecek

results=[123456,654321] and not 432100

Thanks
Have a good day

2 Cevap

Negatif Geriye İlerleme kullanın: \d{6}(?<!00)

See also

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)

Bunun yerine, aşağıdaki kullanın:

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