Home > front end >  Regular expression optimization
Regular expression optimization

Time:12-17


A1=
=c3 + c5 - c26
=c3 + c5 - c26
The following function can adapt to the above situation

Need: improved to adapt to this kind of mixed operation
=c8 + (b10 +...... - b25)

B10 +... - b25 mean b10 accumulation to b24 - b25




 & lt; The table id="TAB" & gt; 






















The function calc (obj) {
Var STR=obj. The innerText;
If (STR [0]=="=") {
Obj. The innerText=eval (STR) slice (1) the replace (([a-z] +)/(\ d +) ([\ + \ \ \ */]) \. {3} \ \ 1 3 (\ d +)/ig, the function (s, a, b, c, d) {
var arr=[];
B=parseInt (b, 10);
D=parseInt (d, 10);
For (var I=b; I & lt;=d; I++)
Arr. Push (a + I);
Return arr. Join (c);
}). Replace (/[a-z] + \ d +/ig, the function (s) {
Return calc (document. GetElementById (s));
}));
}
Return obj. The innerText;
}

Var td=document. QuerySelectorAll (" # TAB td ");
For (var I=0, len=td. Length; I & lt; Len. I++) {
[I] calc (td);
}
</script>
  • Related