Not working code:
var m;
val = "some text with a [tag: in it like that";
m = val.match(/\[\w+:/);
var params = m.substring(1).split(':');
Throws the following error in Firebug:
val.substring is not a function
When I do console.log(typeof(val)); I get object, when I’m expecting a string… at least, I think it should be a string.
How can I perform a .substring() on a “string” from .match() in Javascript?
match()returns an array of strings, containing the complete text of the match followed by the values of any capturing groups.You can call
m[0].substring.