0

I've the following regex

\b(?:\d[ -]*?){5,10}\b

that works but it is also returning numbers that is part of a decimal. The correct responses are shown below but at the moment it is returning all of them. It sees the '.' as a word boundary.

12.123456 = no match

Hello John 124567 = match

12345667 = match
munchine
  • 479
  • 1
  • 9
  • 23

2 Answers2

1

You need to use a negative lookbehind assertion in your regex:

\b(?<!\.)(?:\d[ -]*){5,10}\b

RegEx Demo

(?<!\.) is negative lookbehind assertion that fails the match if dot is immediately before first digit.

anubhava
  • 761,203
  • 64
  • 569
  • 643
0

Use a blanked statement to skip and fail decimals, which causes the match of your
regex. You don't need to pick your regex apart each change you want to make.

(?:\d+(?:\.\d*)|\.\d+)(*SKIP)(*FAIL)|\b(?:\d[ -]*?){5,10}\b

https://regex101.com/r/mP0rxZ/1

Expanded

    (?:
         \d+ 
         (?: \. \d* )
      |  \. \d+ 
    )
    (*SKIP) (*FAIL) 
 |  
    \b 
    (?: \d [ -]*? ){5,10}
    \b