## JavaScript (303 characters compacted, 204 if I'm willing to sacrifice my soul) For clarity, this is the code _before_ I compacted it down ([JS-Fiddle of it](http://jsfiddle.net/IQAndreas/5W3nQ/)): function math(match, leftDigit, operator, rightDigit, offset, string) { var L = parseInt(leftDigit) var R = parseInt(rightDigit) switch (operator) { case '*': return R*L; case '\/': return R/L; case '+': return L+R; case '-': return L-R; } }; multAndDivRegex = /(\-?\d+)([\*\/])(\-?\d+)(?=[^\*\/]*$)/; //Right to left addAndSubRegex = /(\-?\d+)([\+\-])(\-?\d+)/; // Left to right while(multAndDivRegex.test(str)) { str = str.replace(multAndDivRegex, math); } while(addAndSubRegex.test(str)) { str = str.replace(addAndSubRegex, math); } Here it is compacted down to 303 characters ([JS-Fiddle of it](http://jsfiddle.net/IQAndreas/5W3nQ/1/)): function m(x,l,o,r){ L=parseInt(l); R=parseInt(r); switch (o){ case '*': return R*L; case '\/': return R/L; case '+': return L+R; case '-': return L-R; } }; s=prompt(); M=/(\-?\d+)([\*\/])(\-?\d+)(?=[^\*\/]*$)/; A=/(\-?\d+)([\+\-])(\-?\d+)/; while(M.test(s)){s=s.replace(M,m)}; while(A.test(s)){s=s.replace(A,m)}; alert(s) Since I'm ending lines with semi-colons, all _removable_ whitespace was ignored for character counting, but left in for clarity. I can get it down to 204 characters if I use `eval()`, but that's not how I roll... ([JS-Fiddle](http://jsfiddle.net/IQAndreas/2tALa/)) function m(x,l,o,r){L=parseInt(l);R=parseInt(r);switch(o){case '*':return R*L;case '\/':return R/L;}};s=prompt();M=/(\-?\d+)([\*\/])(\-?\d+)(?=[^\*\/]*$)/;while(M.test(s)){s=s.replace(M,m)};alert(eval(s)) This solution would mean that people can enter ANY JavaScript code they want! The 303 character version does not execute any JavaScript; it only does math.