I need some help to build an array from a shortcode. The problem is the match regex part.
my short code looks like this:
[email_image,id=1,c=member,fS=15,lH=20]
desired output:
{name: 'email_image', id: '1', c: 'member', fS: '15', lH: '20'}
How to alter my function (regex) to work?
thanks.sepp.
function ajax(ed){
var str = tinyMCE.activeEditor.getContent();
var re = /\[email_image([^\]]*)\]/g;
var found = str.match(re);
found.map(function(item){
//console.log(item); // [email_image,id=1,c=member,fS=15,lH=20] ....
arraytophp = {name: 'email_image', id : item.split(',')[1].split('=')[1], c: item.split(',')[2].split('=')[1], fS : item.split(',')[3].split('=')[1], lH: item.split(',')[4].split('=')[1].replace(']','')};
// PROBLEM START *************************************************************
var arraytophp_test = {};
item.match(/([\w-]+)=([^,]+)/g).forEach(function(attribute) {
//console.log(attribute)
attribute = attribute.match(/([\w-]+)=(.+?)/);
arraytophp_test[attribute[1]] = attribute[2];
});
console.log(arraytophp_test);
// PROBLEM END **************************************************************
jQuery.ajax({
url: "StringImage_Ajax/ajaxImage",
type: "POST",
dataType: "json",
async:false,
data: {"data" : JSON.stringify(arraytophp)}
}).done(function(data){
string = data.string;
tinyMCE.activeEditor.setContent(tinyMCE.activeEditor.getContent().replace(item,string));
});
});
}
function(attribute)withfunction(match_val, attribute1, attribute2)and then useattribute1instead ofattribute[0]andattribute2instead ofattribute[1]