Skip to content

Instantly share code, notes, and snippets.

@kontur
Created July 28, 2014 11:17
Show Gist options
  • Save kontur/9fcbaef1b7396927d569 to your computer and use it in GitHub Desktop.
Save kontur/9fcbaef1b7396927d569 to your computer and use it in GitHub Desktop.
Javascript regexp to extract matrix values from a String into an Array
// via http://stackoverflow.com/a/14397066/999162
var matrixToArray = function(str){
return str.match(/(-?[0-9\.]+)/g);
};
matrixToArray('rgba(0, 0, 0, 0.5)'); // => ['0', '0', '0', '0.5']
matrixToArray('matrix(1, 0, 0, 1, -770, 0)'); // => ['1', '0', '0', '1', '-770', '0']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment