pangpang
pangpang

Reputation: 8821

python regular expression get numbers except decimal

I want to get the greater than or equal to 6 digit number, but ignore the decimal. For example:

123 => invalid
123456 => 123456
123456.12 => invalid
abcd1234567efg => 1234567
abcd1234567.123efg => invalid

How do I use python regular-expressions to do it?

Upvotes: 1

Views: 86

Answers (1)

Learner
Learner

Reputation: 5292

I would use negative/positive look ahead and alternation

\d{6,}(?=\D)(?!\.)|\d{6,}(?=$)

DEMO LIVE

Upvotes: 2

Related Questions