I'm trying to create a bbcode filtering solution that works with both PHP and Javascript. Right now I'm working on the javascript. I'm having trouble getting the new RegExp constructor to recognize the patterns in my json. Here's a small bit of sample code that reproduces the issue. Any insight would be greatly appreciated!
bbcode.json
{"bbcode_regex": [
{"regex": "<p>", "bbcode": ""},
{"regex": "<\/p>", "bbcode": ""},
}
global.js
function html2bbcode(html) {
var bbcode = html;
jQuery.get("bbcode.json", {}, function(json) {
for(var i in json.bbcode_regex) {
bbcode = bbcode.replace(new RegExp(json.bbcode_regex[i].regex, "g"), json.bbcode_regex[i].bbcode)
console.log(new RegExp("/<p>/"));
}
}, 'json');
return bbcode;
}
Note that I'm using FireBug and the console.log RegExp is there just for experimenting / debug purposes. It seems like no matter what I put in as the first argument for the new RegExp it only logs an empty object like {}. I'm no so much worried about the PHP right now, just the javascript. Thanks!