regex - Javascript to pull attributes from shortcode string -
i have javascript application retrieves shortcode stings wordpress database. may end variable this: var shortcode = '[wp-form id="1946" title="my test form"]'; i looking use pure javascript access attributes can extract title, etc. imagine form or regex , split(). far efforts frustrated splitting whitespace. any ideas appreciated. try use code: var shortcode = '[wp-form id="1946" title="my test form"]'; var attributes = {}; shortcode.match(/[\w-]+=".+?"/g).foreach(function(attribute) { attribute = attribute.match(/([\w-]+)="(.+?)"/); attributes[attribute[1]] = attribute[2]; }); console.log(attributes); output: object {id: "1946", title: "my test form"}