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"} 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo