var re = /^\[*:*\]*/;
alert(re.test("aa"));
Always alerts true (on any string). What am i doing wrong? I need to check is there something like [445:123] in the beginning of the string.
Your regex means
[ characters ...: characters ...] characters.The string "aa" matches that. You probably want something like:
var re = /^\[\d+:\d+\]/;
The + quantifier means "one or more", while * means "zero or more". The \d escape means "any digit".
*edit — if the regex needs to match something like
[12:2:17:419]
as well, then it would be
var re = /^\[\d+(:\d+)+\]/;
/^\[\d*:\d*\]/in regular expressions, * does not mean wildcard match, it means zero or more of the previous token. To match any character, use . instead. A regex for what you want to match is more like this...
/^\[.*:.*\].*/
But better is to be more specific, using \d to match decimals, and use + to match one or more of the previous token, and remove the erroneous characters after the match...
/^\[\d+:\d+\]/
[then zero or more:, then zero of more].aadoes contains 0 or more of the above. What are you trying to test here?