user3044394 user3044394 - 1 month ago 5x
Javascript Question

find multiple digits and a colon within a string using regex

I'm trying to find any string of digits followed by a colon.
Here is an example string:

var str = " 234: all kinds of code";

Here is what I tried:^\d+:$/);

and that returns a -1 so it is not finding the digits followed by the colon.

I tried this and it returned 0:



Your regex is only successful when the string to search begins and ends with digits followed by colon. Try this:\d+:/);