Bryntum Quiz 4

by Alexander Novikov

HTML

<script src="https://getfirebug.com/firebug-lite-debug.js"></script>

JavaScript

/*
4. Write a RegExp to extract the x, y, z offset values from these CSS style declarations:

translate3d(0, 0, 0)
translate3d(0,    0,     0)
translate3d(1px, 10px, 100px)
translate3d(-1px, -10px, -100px)

The x, y, z offsets should be numbered as 1, 2, 3 in the RegExp match object. Strings of other formats should not match.
*/

var declarations = [
    'translate3d(0, 0, 0)',
    'translate3d(0,    0,     0)',
    'translate3d(1px, 10px, 100px)',
    'translate3d(-1px, -10px, -100px)'
];

var positionRegExp = /translate3d\((-{0,1}\d+)(?:px){0,1},\s+(-{0,1}\d+)(?:px){0,1},\s+(-{0,1}\d+)(?:px){0,1}\)$/;

for (var i=0, iMax=declarations.length; i<iMax; i++) {
     
     console.log( declarations[i].match(positionRegExp) ) ;
     
}