jQuery regex help
I need some simple help with regex I want to grab the values in between brackets and equal sign开发者_JS百科s.
<a href="[url=img.php?i=1][pod=2]">My Link</a>
then grab the values of url = img.php?i=1 and pod = 2
so somehow regex should check in between [ and = then get the value in between = and ]
var matches = "<a href=\"[url=img.php?i=1][pod=2]\">My Link</a>".match(/\[url=(.*)]\[pod=(.*)\]">/);
var url = matches[1]; // == img.php?i=1
var pod = matches[2]; // == 2
There you go!
try out this sample for yourself - http://jsfiddle.net/ENwf8/
var string = "[url=img.php?i=1][pod=2]";
var regEx = /\[(.*?)=(.*?)]\[(.*?)=(.*?)]/;
var matches = string .match(regEx);
for (index = 0; index < matches.length; index++) {
document.write(index + ": " + matches[index] + "<br>");
}
prints:
0: [url=img.php?i=1][pod=2]
1: url
2: img.php?i=1
3: pod
4: 2
精彩评论