var temp = "/User/Create";
alert(temp.count("/")); //should output '2' find '/'
i will try this way
// the g in the regular expression says to search the whole string
// rather than just find the first occurrence
// if u found User -> var count = temp.match(/User/g);
// But i find '/' char from string
var count = temp.match(///g);
alert(count.length);
u can try here http://jsfiddle.net/pw7Mb/
You would need to escape the slash in regex literals:
However, that could return
nullif nothing is found so you need to check for that:A shorter version could use
split, which returns the parts between the matches, always as an array: