regex - Parse SVG transform attribute with javascript -


supposing have svg transform string:

transform = "translate(6,5),scale(3,3)"; 

is there slick regex function use parse usable?

here's nifty little snippet of code might need, should cover scenario in case string intend parse has different number of arguments:

function parse (a) {     var b={};     (var in = a.match(/(\w+\((\-?\d+\.?\d*e?\-?\d*,?)+\))+/g))     {         var c = a[i].match(/[\w\.\-]+/g);         b[c.shift()] = c;     }     return b; } 

running this

parse('translate(6,5),scale(3,3.5),a(1,1),b(2,23,-34),c(300)'); 

will result in this:

{     translate: [ '6', '5' ],     scale: [ '3', '3.5' ],     a: [ '1', '1' ],     b: [ '2', '23', '-34' ],     c: [ '300' ] } 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -