PHP regex:Find all 6 digit numbers in a string that do not end in 00
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 dayUse 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])/
精彩评论