Find translate attribute from a transform string

When working with svg object and all svg object have a standard transform like that:move(x,y) translate(x,y) scale(x) rotate(x)...

A transform spec can be found at W3 SVG Transform Attribute, we can see translate(<tx> [<ty>]), which specifies a translation by tx and ty. If <ty> is not provided, it is assumed to be zero.

I have a regular expression to extract a translate from transform string:\s?translate((-?\d.?\d),?\s?(-?\d.?\d)?)\s?
This is an example in javascript:
var regExp = /\s?translate((-?\d.?\d),?\s?(-?\d.?\d)?)\s?/ig;
var transform = 'move(1,2) translate(10.3,2)';
var match = regExp.exec(transform);
window.console && console.log(match); // Open firebug and view output

At the moment, it is very good for me. I'll update to find better solution.

Categogy: 

Tags: 

Add new comment