0

I have expression which looks like:

((type file1.csv file2.csv | Test +) & (type file3.csv file4.csv | Test +)) | Test + |Test sum | Test transpose | Test sum

The expression has many nested parenthesis and other special characters like

|
&

I want to evaluate the expression above in C# in this order:

1. (type file1.csv file2.csv | Test +)
2. (type file3.csv file4.csv | Test +)
3. 1 & 2 | Test +
4. 3 | Test sum
5. 4 | Test transpose
6. 5 | Test sum

I have referred to the sample solution shown here: Solution using the Regex as below: \(([^()]*)\)

How do I modify the regex above to consider | and &?

Thank you

user2150279
  • 445
  • 2
  • 8
  • 17
  • 1
    What about [`(?<!\([^)]*)[|&]`?](http://regexstorm.net/tester?p=%28%3f%3c!%5c%28%5b%5e%29%5d*%29%5b%7c%26%5d&i=%28%28type+file1.csv+file2.csv+%7c+Test+%2b%29+%26+%28type+file3.csv+file4.csv+%7c+Test+%2b%29%29+%7c+Test+%2b+%7cTest+sum+%7c+Test+transpose+%7c+Test+sum%0d%0a) Not sure what you mean otherwise... – ctwheels Mar 06 '18 at 17:49
  • 3
    Parsing algebraic expressions cannot be done with one Regex pattern. You have to follow algebraic rules so you properly parse correctly following hierarchical rules. – jdweng Mar 06 '18 at 18:06
  • @jdweng, what solution do you propose to parse the expression? – hunterex Mar 06 '18 at 18:25
  • It really would help if you explained what “to evaluate the expression” means. Do you want to return a list or something of strings? You want to do something with each string? – Dour High Arch Mar 06 '18 at 18:39
  • I Wasn't proposing a solution. Just indicating the proposed solution won't work. See wiki for correct way of parsing using grammar : https://en.wikipedia.org/wiki/Parsing_expression_grammar – jdweng Mar 06 '18 at 18:52
  • @Dour_high_arch, "to evaluate the expression" means I want to return a list of string (order of string in the list) matters. I want to evaluate each list element in the list as shown in my original post (no 1 to no 6) – user2150279 Mar 06 '18 at 18:54

0 Answers0