user3044394 user3044394 - 1 year ago 63
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:


Answer Source

Your regex is only successful when the string to search begins and ends with digits followed by colon. Try this:\d+:/);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download