LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Mathematical formula parsing with regex

Solved!
Go to solution

Hello,

 

I want to extract the operands from a mathematical formula. I've written the regex in attached the attached snippet.

 

If one of the operand is BbBb[126] everything is fine (extracted operand = BbBb[126]) , but if the number is BbBb[-126] then I have two operands extracted (BbBb[ and 126]) instead of BbBb[-126]. I cannot figure how to exclude the match of the minus sign if it is between [] while keeping the match of other operators * + / ^ - 😞

 

The idea of the regex is to find and replace BbBb AaaAA etc by a0, a1 etc. to be compatible with eval formula node.

 

thank you and best regards.

 

best regards

0 Kudos
Message 1 of 3
(1,983 Views)
Solution
Accepted by topic author haha1234

Just tweak the regex to use a negative look-behind.

 

(\+|(?<![[])\-|\*|\/|\^)

 

matches alternatives, either '+', '-' not preceded by '[', '*', '/' or '^'

Message 2 of 3
(1,909 Views)

thank you Darin, that solved my problem.

 

My mind was stuck in trying to find minus operators BETWEEN brackets, while I should just find the opening bracket just BEFORE the minus operator.

0 Kudos
Message 3 of 3
(1,900 Views)