Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a fragile attempt to use regular regular expressions and recursion: </p> <pre><code>static class Program { static void Main(string[] args) { string prefix = "&gt;"; string suffix = "&gt;"; string subject = "Subject&gt;memberName1&gt;memberName2&gt;member&gt;Name3&gt;EndSubject"; var result = Find(subject, true, prefix, suffix).ToList(); result.ForEach(item =&gt; { Console.WriteLine(item); }); /* The output is: memberName1&gt;memberName2 member&gt;Name3 *match memberName1 *match memberName2 *match member Name3 */ } private static IEnumerable&lt;string&gt; Find( string subject, bool toggle, string prefix, string suffix) { string r1 = @"(?&lt;=" + prefix + @")(?&gt;([\w]*(" + prefix + "|" + suffix + @")[\w]*))(?=" + suffix + ")", r2 = @"[\w]*"; var temp = Regex.Matches(subject, toggle ? r1 : r2 ) .Cast&lt;Match&gt;() .ToList(); return temp.SelectMany(m =&gt; temp .Select(i =&gt; i.Value) .Union(Find(m.Value, !toggle, prefix, suffix))) .Where(s =&gt; !String.IsNullOrEmpty(s)) .Distinct(); } } </code></pre> <p><em>Note: I'm not sure if in your example, the <code>&gt;</code> in <code>member&gt;Name3</code> is considered a prefix or a suffix.</em></p> <p>[EDIT] Here's another approach, which doesn't use regular expressions. It takes into account that the <code>&gt;</code> in the <code>member&gt;Name3</code> could be a prefix <strong>or</strong> a suffix:</p> <pre><code>var separators = new[] { prefix, suffix }; var firstResult = separators .SelectMany(s =&gt; subject .Split(separators,StringSplitOptions.RemoveEmptyEntries) .Skip(1) .Reverse() .Skip(1) .Reverse()) .Distinct() .ToList(); var result = firstResult .Zip(firstResult.Skip(1), (a, b) =&gt; { var l = new List&lt;string&gt;(); separators.ToList().ForEach(s =&gt; { l.Add(String.Format("{0}{1}{2}", a, s, b)); }); return l; }) .SelectMany(s =&gt; s) .Union(firstResult) .ToList(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload