Regex to get first number in string with other characters

/^[^\d]*(\d+)/

This will start at the beginning, skip any non-digits, and match the first sequence of digits it finds

EDIT:
this Regex will match the first group of numbers, but, as pointed out in other answers, parseInt is a better solution if you know the number is at the beginning of the string

Leave a Comment