I have a problem with a javascript regexp. This is my regex:
(([\+\-\/\*\^]?)([(]*(([(]?((([+-]?\d+([.,]?(\d+)?)?)|(Q[0-9]+)?)([e][+-]\d+)?)[)]?)|([(]?value[)]?))[)]*)?(([(]*([(]?((([+-]?\d+([.,]?(\d+)?)?)|(Q[0-9]+)?)([e][+-]\d+)?)[)]?)|([(]?value[)]?)[)]*))?([\+\-\/\*\^])([(]*(([(]?((([+-]?\d+([.,]?(\d+)?)?)|(Q[0-9]+)?)([e][+-]\d+)?)[)]?)|([(]?value[)]?))[)]*))+
This regexp test if the text is an matematical formula (18*19)/2
for example, and I can add QXX
like a variable, for example:
Q18/42+7*Q7
This regexp work perfectly in java (I have tested it on http://fiddle.re/dnbh6). But, when I tried to convert it in javascript, it doesnt work... This is all solutions that I tried:
var reg =/(([\+\-\/\*\^]?)([(]*(([(]?((([+-]?\d+([.,]?(\d+)?)?)|(Q[0-9]+)?)([e][+-]\d+)?)[)]?)|([(]?value[)]?))[)]*)?(([(]*([(]?((([+-]?\d+([.,]?(\d+)?)?)|(Q[0-9]+)?)([e][+-]\d+)?)[)]?)|([(]?value[)]?)[)]*))?([\+\-\/\*\^])([(]*(([(]?((([+-]?\d+([.,]?(\d+)?)?)|(Q[0-9]+)?)([e][+-]\d+)?)[)]?)|([(]?value[)]?))[)]*))+/g;
reg.test("Q18+aaaa)//return true, but in java this is resturn false
var reg= new RegExp("(([\+\-\/\*\^]?)([(]*(([(]?((([+-]?\d+([.,]?(\d+)?)?)|(Q[0-9]+)?)([e][+-]\d+)?)[)]?)|([(]?value[)]?))[)]*)?(([(]*([(]?((([+-]?\d+([.,]?(\d+)?)?)|(Q[0-9]+)?)([e][+-]\d+)?)[)]?)|([(]?value[)]?)[)]*))?([\+\-\/\*\^])([(]*(([(]?((([+-]?\d+([.,]?(\d+)?)?)|(Q[0-9]+)?)([e][+-]\d+)?)[)]?)|([(]?value[)]?))[)]*))+", "g");
reg.test("Q18+aaaa)//return true, but in java this is resturn false
So, if you had any idea, i will try it.