There are topics on Stack Overflow on how to match a number of a certain length, but that's not what I'm trying to do.
I'd like to match a number that has 5-digits or more but not if it's followed or preceded by anything other than numbers.
There are topics on Stack Overflow on how to match a number of a certain length, but that's not what I'm trying to do.
I'd like to match a number that has 5-digits or more but not if it's followed or preceded by anything other than numbers.
You can use \d{5,}
, which matches 5 digits or more, then:
\b\d{5,}\b
. \b
matches word boundaries.^\d{5,}$
. ^
matches the beginning of the line while $
matches its end.Here is an example.
Use ^ for the start of string and $ for the end of string.
/^[\d]{5,}$/
So string of '12354' is true but string of '12345 foo' is false. Is it your question?
I hope this is what you're looking for
/(?<=\d\s)\d{5,}(?=\s\d)/g
Explanation:
(?<= look behind to see if there is:
\d digits (0-9)
\s whitespace (\n, \r, \t, \f, and " ")
) end of look-behind
\d{5,} digits (0-9) (at least 5 times)
(?= look ahead to see if there is:
\s whitespace (\n, \r, \t, \f, and " ")
\d digits (0-9)
) end of look-ahead
Or something more complicated
/(?<=\d(?:\s))\d{5,}(?=\s(?:\d))/g