I’m trying to match a Number in between a set of straight brackets, example:
Match the 0 in actionFields[actionFields][0][data[Report][action]]
This is what I have so far and I keep getting null.
var match, matchRegEx = /^\(?\[(\d)\]\)$/;
nameAttr = "actionFields[actionFields][0][data[Report][action]]",
match = matchRegEx.exec(nameAttr);
If you look at your regular expression, you’re matching the beginning of the string, zero or one
(, then a[, then a\d, then a], then a), then the end of the string.You should just be able to get away with
/\[(\d)\]/, unless you’re expecting the[0]construct to show up elsewhere in your string.Here’s a RegexPal showing this.