Q:

How to extract group of numbers from a phrase using regex?

I have multiple sentences which look like the following sentence - 
069054 my name is black fox, $1234. phone number:1234567
I need to extract to extract the first word (or numbers, in this example its 069054).
The conditions that needs to be met are:

it should only consist of 6 digits.
It should be the first thing in the sentence.
If it has more or less digits, i should ignore it.
should only consist of numbers, no chars allowed

Here is what i have, but its not working out for me. 
^([\d]{6})$

A:

This is the regex you are looking for:
^(\d{6})(?!\d)

Just remove the $ from the end and replace it with (?!\d). It means the six digits which are not followed by any digit.
If you wish to avoid picking digits from input like 123456xyz then use this one:
^(\d{6})(?![\da-zA-Z])

