Reputation: 502
the goal here is finding all numeric values of length 5 to 8. decimal and comma is allowed between them. this is the expression i same how made:
\b[0-9](,?\.?\d){4,7}\b(?!,\d)
it working fine except it is matching 10,000,02332 for 000,02332. i tried both lookbehind and ^ but it seem i am making some mistake.
here is sample text
- Nunc 12vitae lac332us sollicitudin 2033112233, varius 100212 ipsum a, gravida 10,000,02332 ante. Nunc et 100,021 justo eget arcu fringilla fermentum id venenatis lacus. Pellentesque a 23133221 tellus vel diam dignissim scelerisque123 nec ac2 12311 ipsum. Fusce at 12311.1 dui ut odio posuere 1233312234666 condimentum. Nulla 4564quis viverra 568833452233 nunc. Morbi 234322123 imperdiet, nulla adipiscing interdum venenatis, dui mi 2341112333 congue erat, sed 34234112323 suscipit est 345221 turpis in lorem. Proin magna123 nunc, 1231116565 rhoncus sit amet elit a, fermentum 5467667834533 semper felis. Integer non elit placerat metus fermentum auctor. Donec viverra enim in augue adipiscing, eget facilisis 3422211 ligula 12313645 vulputate. Maecenas tincidunt 2346776444 posuere pretium. Donec euismod cursus velit. ,11111
you can test it here: http://gskinner.com/RegExr/
Upvotes: 0
Views: 137
Reputation: 13353
Can this fit you ? It does not look like that complicated.
\b\d[\d,.]{3,7}\d\b
Upvotes: 1
Reputation: 55589
Try adding (?<!\d[,.])
to the front of your regex and changing (?!,\d)
to (?![,.]\d)
.
Giving you:
(?<!\d[,.])\b[0-9](,?\.?\d){4,7}\b(?![,.]\d)
(?<!\d[,.])
is negative look-behind checking for a digit followed by a comma or a full-stop.
I changed the negative look-ahead to check for a full-stop as well, since otherwise the first part of 12345678.3
will match.
Test.
Upvotes: 2