I am trying to integrate a small REST API in into my C# application, which allows filtering on different columns.
I have a string I need to split into an array using the | (pipe) as demiliter.
It should split on every string, EXCEPT if it is enclosed in a quoted string.
Example of a string A_TAG|A_DESC|A_AREA1≈”|“|F_CV
This should be split into 4 substrings:
A_TAG
A_DESC
A_AREA1≈”|”
F_CV
I have tried different RegEx’s without success (even tried CoPilot).
It seems like all tries will split on the pipe in the string as well.
What i have tried is something like this:
This question is almost similar, but it still splits inside the enclosed string:
How to split a string with delimited as pipe (which is not inside double quotes
string input = "A_TAG|A_DESC|A_AREA1≈"*|*"|F_CV";
string pattern = @"(?<="")[^""]*(?="")|[^|]+";
var result = Regex.Matches(input, pattern)
.Cast<Match>()
.Select(m => m.Value)
.ToArray();
Anyone has any suggestions