I have this string in C#
adj_con(CL2,1,3,0),adj_cont(CL1,1,3,0),NG, NG/CL, 5 value of CL(JK), HO
I want to use a RegEx to parse it to get the following:
adj_con(CL2,1,3,0)
adj_cont(CL1,1,3,0)
NG
NG/CL
5 value of CL(JK)
HO
In addition to the above example, I tested with the following, but am still unable to parse it correctly.
"%exc.uns: 8 hours let @ = ABC, DEF", "exc_it = 1 day" , " summ=graffe ", " a,b,(c,d)"
The new text will be in one string
string mystr = @"""%exc.uns: 8 hours let @ = ABC, DEF"", ""exc_it = 1 day"" , "" summ=graffe "", "" a,b,(c,d)""";
Assuming non nested, matching parentheses, you can easily match the tokens you want instead of splitting the string:
The TextFieldParser (msdn) class seems to have the functionality built-in:
See the article which helped me find that
Just this regex:
A test example:
returns
Another way to implement what Snowbear was doing:
The idea is to replace any non-nested delimiter with another delimiter that you can then use with an ordinary
string.Split()
. You can also choose what type of bracket to use -()
,<>
,[]
, or even something weird like\/
,][
, or`'
. For your purposes you would useThe function would first turn your string into
then split on the
~
, ignoring the nested commas.If you simply must use Regex, then you can split the string on the following:
It breaks your input into the following:
You can also use .NET's balanced grouping constructs to create a version that works with nested parens, but you're probably just as well off with one of the non-Regex solutions.