Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let me know if I should delete the old post, but perhaps someone wants to read it. </p> <p>The way to do a "words to look for" inside the regex is like this:</p> <pre><code>regex = @"(Key1|Key2|Key3|LastName|FirstName|Etc):" </code></pre> <p>What you are doing probably isn't worth the effort in a regex, though it can <em>probably</em> be done the way you want (still not 100% clear on requirements, though). It involves looking ahead to the next match, and stopping at that point.</p> <p>Here is a re-write as a regex + regular functional code that should do the trick. It doesn't care about spaces, so if you ask for "Key2" like below, it will separate it from the value. </p> <pre><code>string[] keys = {"Key1", "Key2", "Key3"}; string source = "Key1:Value1Key2: ValueAnd A: To Test Key3: Something"; FindKeys(keys, source); private void FindKeys(IEnumerable&lt;string&gt; keywords, string source) { var found = new Dictionary&lt;string, string&gt;(10); var keys = string.Join("|", keywords.ToArray()); var matches = Regex.Matches(source, @"(?&lt;key&gt;" + keys + "):", RegexOptions.IgnoreCase); foreach (Match m in matches) { var key = m.Groups["key"].ToString(); var start = m.Index + m.Length; var nx = m.NextMatch(); var end = (nx.Success ? nx.Index : source.Length); found.Add(key, source.Substring(start, end - start)); } foreach (var n in found) { Console.WriteLine("Key={0}, Value={1}", n.Key, n.Value); } } </code></pre> <p>And the output from this is:</p> <pre><code>Key=Key1, Value=Value1 Key=Key2, Value= ValueAnd A: To Test Key=Key3, Value= Something </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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