0

So i've been having trouble with finding a solution to this task: I need to split out the following example string:

(item:940x1 || (item:941x1 && item:935x2)) && item:942x2 && (item:123x1 && item:123x1)

into the following array of strings:

(item:940x1 || (item:941x1 && item:935x2)) //Will split this nested group later
item:942x2
(item:123x1 && item:123x1) //Do not need the parenthesis here retained. Can be removed after splitting.

I've tried various ways to split it, including Regex(which i was told doesn't handled nested patterns). Does anyone have a good solution?

  • Maybe splitting the string is not the best way to do what you want? It looks like you're giving some sort of "framework" where users can set conditions? – Stefan May 10 '20 at 13:43
  • Not sure if it is a solution to your problem, but in .NET you can use a [regex with balancing groups](https://learn.microsoft.com/en-us/dotnet/standard/base-types/grouping-constructs-in-regular-expressions#balancing_group_definition) – The fourth bird May 10 '20 at 14:03
  • @Stefan no i'm trying to display visual information for a set of "requirements" from a string that needs to be parsed. – Vincent Hong May 11 '20 at 00:59
  • @VincentHong Well maybe this (https://stackoverflow.com/questions/17568067/how-to-parse-a-boolean-expression-and-load-it-into-a-class) might help. Anyway, if you have the information in non-string, let's say some requirement objects, form it might be easier. – Stefan May 11 '20 at 05:31

0 Answers0