Regex to match a digit not followed by a dot(".")

Viewed 5213

I have a string

string 1(excluding the quotes) -> "my car number is #8746253 which is actually cool"

conditions - The number 8746253, could be of any length and
- the number can also be immediately followed by an end-of-line.

I want to group-out 8746253 which should not be followed by a dot "."
I have tried,

.*#(\d+)[^.].*

This will get me the number for sure, but this will match even if there is a dot, because [.^] will match the last digit of the number(for example, 3 in the below case)

string 2(excluding the quotes) -> "earth is #8746253.Kms away, which is very far"

I want to match only the string 1 type and not the string 2 types.

2 Answers
Related