I have a DIV with element id; e.g. “bgjhkn2n2-20”. I’m trying to get the regex right so I can load reports dynamically into div’s based on id.
console.log(elemID) prints the bgjhkn2n2-20 as expected. It’s not printing the # that normally prefixes element Id. console.log(repDBID[0]) prints the full element ID; but I can not get firebug to print the groups I get from a similar test in a regextester with console.log(repDBID[0]). If I append an index number to the match statement, it returns null.
Help?
var baseURL = window.location.protocol + "//" + window.location.hostname + "/db/";
var genREP = "?a=API_GenResultsTable&qid=";
$('#tab1 div').each(function (e){
var elemID = this.getAttribute('id');
console.log(elemID);
var pattern=/([a-z0-9]{9})-([1-9]{1}[0-9]*)/g
var repDBID = elemID.match(pattern); //get dbid
console.log(repDBID[0]);
var repID = elemID.match(pattern)[2]; //get qid
//console.log(repID);
//$(this).load(baseURL+repDBID+genREP+repID);
$('#repTabs').tab(); //initialize tabs
});
Remove the
gfrom your regex and it should work just fine:Here’s what I mean: