Javascript Regular Expression and square brackets
I have a string that I need to get a number from.
this is my string:
alphanumeric|minlength[2]|maxlength[7]
I need to get the minlength number. (I don't always know what the minlength number will be)
How can I do this with a javascript regular expression?
Here's my full javascript 开发者_如何学JAVAcode:
var attributes = e.attr('data-validate');
var pattern = /minlength\[(\d+)\]\/;
var params = attributes.match(pattern);
console.log(params);
The following should match what you want. And, it will capture the number in brackets that you want.
/minlength\[([^\]]+)\]/
精彩评论