Friday, 9 August 2013

.Net Regex to nested struct

.Net Regex to nested struct

I'm trying to do a regex that can give me the following result:
Text: [Add Months([Actual Date], 5)] - Another Text - [Actual Date] -
[Cria ocorrencia padrao.Record.Name] - Another Text - [Add Months([Actual
Date], 5, [Actual Date])] - [Add Months(Add Days(AddDays([Actual Date],
5), 7), 5, [Actual Date])] - final text
Match 1: [Add Months([Actual Date], 5)]
Match 2: - Another Text -
Match 3: [Actual Date]
Match 4: -
Match 5: [Cria ocorrencia padrao.Record.Name]
Match 6: - Another Text -
Match 7: [Add Months([Actual Date], 5, [Actual Date])]
Match 8: -
Match 9: [Add Months(Add Days(AddDays([Actual Date], 5), 7), 5, [Actual
Date])]
Match 10: - final text
But I don't have success and I need to do this task.
I'm tryng to use the nested pattern regex in .Net using this regex:
string pattern =
@"(([^\[\]]*)??)|(\[(?>\[(?<DEPTH>)\](?<-DEPTH>)|.?)*(?(DEPTH)(?!))\])?([^\[\]]*)";
But is not working, someone can give me a light?
Thank you.

No comments:

Post a Comment