Python Regex To Find Arithmetic Expressions In Text Strings
I try to find arithmetic expressions in text strings. Possible arithmetic expression: 1/3 + 1/4 cos(30) + 25*3,75 sqrt(5) + sin(45) 5 != 6 2**4 + 100.000 = (2^3)^4 sqrt((0,25*8)/2)
Solution 1:
An example using recursive regex
([\d,.e]+|(cos|sin|sqrt)\((?R)\)|\([ ]*(?R)[ ]*\))([ ]*[-+*\/!=^]+[ ]*(?R))*
Could be improved to be more strict to match operators or numbers
(?R)
refering recursively the whole regex
Post a Comment for "Python Regex To Find Arithmetic Expressions In Text Strings"