Skip to content

Instantly share code, notes, and snippets.

@torifat
Last active August 29, 2015 14:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torifat/cbaedae3d0256b0f97d5 to your computer and use it in GitHub Desktop.
Save torifat/cbaedae3d0256b0f97d5 to your computer and use it in GitHub Desktop.
var str = "[ 70W [ 50H [ 50W + 50W ] + 25H + 25H ] + 30W ]";
str = str.replace(/([\d]+)(W|H)/g, function(match, t1, t2) {
var attr = (t2 === 'H') ? 'height' : 'width';
return '<div ' + attr + "='" + t1 + "%'>";
}).replace(/(]|\+)/g, '</div>').replace(/(\[)/g, '');
console.log(str);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment