Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
<div class="form-group form-col-2">
	{{<div class="form-group-inline">
		<label>{{ABCDEF}}</label>
		<div class="inpt">
		{{??DropList??}}
			
		{{??DropList??}}
		</div>
	</div>}}                                        
</div>
<div class="form-group form-col-2">
	{{<div class="form-group-inline">
		<label>{{DEFGHI}}</label>
		<div class="inpt">
		{{??DropList??}}
			
		{{??DropList??}}
		</div>
	</div>}}                                        
</div>


What I have tried:

i just need as follws
1)
{{<div class="form-group-inline">
		<label>{{ABCDEF}}</label>
		<div class="inpt">
		{{??DropList??}}
			
		{{??DropList??}}
		</div>
	</div>}} 

2)
{{ABCDEF}}

3)
{{??DropList??}}

4)
{{??DropList??}}
Posted
Updated 16-Nov-17 1:13am

Quote:
How to split following data based on matches of curly bracket (start and over) USING C# or REGEX

In order to do this with regEx, you need to use a RegEx package that support recursive patterns.
Recursive Regex—Tutorial[^]
Regular Expression Recursion[^]
Capturing with Regular Expression Recursion and Subroutines[^]

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
 
Share this answer
 
This may not be an excellent solution but it matches your demand, Regex is not used here

string file = @"D:\Projects\CPTemp\CPTemp\TextFile1.txt";
           string data = File.ReadAllText(file);
          var parts=  data.Split( new string[] {"{{<div "} , System.StringSplitOptions.None);
          foreach (string item in parts)
          {
              string result1 = "{{<div " + item;
              if (result1.Contains("</div>}} "))
              {
                  result1 = result1.Substring(0, result1.IndexOf("</div>}}"));
                  result1 += "</div>}}";
                  /*{{<div class="form-group-inline">
                       <label>{{ABCDEF}}</label>
                       <div class="inpt">
                       {{??DropList??}}

                       {{??DropList??}}
                       </div>
                   </div>}} */

                  string result2 = result1;
                  result2 = result2.Substring(result2.IndexOf("<label>") + 7, (result2.IndexOf("</label>") - result2.IndexOf("<label>") - 7));  // {{ABCDEF}}

                  string result3 = result1;
                  result3 = result3.Substring(result3.IndexOf("<div class=\"inpt\">") + 18 ,result3.IndexOf("</div>") -result3.IndexOf("<div class=\"inpt\">") -18   );
                  result3 = result3.Trim();
                  var partsLast = result3.Split('\n').Where(k => !string.IsNullOrWhiteSpace(k.Trim())).ToArray();

                  result3 = partsLast[0].Trim();  //{{??DropList??}}

                  string result4 = partsLast[1].Trim(); //{{??DropList??}}


              }
          }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900