I have the following Javascript
function myFunction() {
var str = "depth10 shown";
var depth= str.match(/^depth[\d+$]/);
console.log(depth);
}
My function is trying to find if depth* is present in the string, where * is always numeric (ex: depth0, depth1, depth100) and return the numeric value in it. In the example above, depth is always returning only one digit instead of all digits. Can anyone explain why?
[\d+$]will match a digit or plus or$^depth\d+$and^depth(\d+)$Leave out the^and$anchors to see how those differ.