Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>if(match.Success &amp;&amp; (match.Length &gt; struct.dlugosc)) </code></pre> <p>The Match's length is never going to be longer than the struct's length - the struct's length at minimum is that of the string, plus all the other items in it.</p> <p>What else were you testing for after match.Success?</p> <p>If you want some matching code for what I think you're asking for, the following works a charm:</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Text.RegularExpressions; namespace Word_Ending_Finder { public partial class Form1 : Form { private List&lt;string&gt; WordsToFind = new List&lt;string&gt;(); private List&lt;MySpecialStringStruct&gt; PassagesToSearch = new List&lt;MySpecialStringStruct&gt;(); public Form1() { InitializeComponent(); PassagesToSearch.Add(new MySpecialStringStruct("This is a test passage with a test ending.", 0)); PassagesToSearch.Add(new MySpecialStringStruct("This is a second test passage with a test ending.", 0)); PassagesToSearch.Add(new MySpecialStringStruct("This is a third passage that won't match.", 0)); WordsToFind.Add(@"ing\b"); WordsToFind.Add(@"\bsecond\b"); WordsToFind.Add(@"\bgarbage text\b"); } private void bnGo_Click(object sender, EventArgs e) { txtResults.Text = ""; string Separator = "------------------------------------------"; StringBuilder NewText = new StringBuilder(); foreach (string SearchWord in WordsToFind) { NewText.AppendLine(string.Format("Now searching {0}", SearchWord)); List&lt;MatchValue&gt; Results = FindPassages(PassagesToSearch, SearchWord); if (Results.Count == 0) { NewText.AppendLine("No Matches Found"); } else { foreach (MatchValue ThisMatch in Results) { NewText.AppendLine(string.Format("In passage \"{0}\":", ThisMatch.WhichStringStruct.Passage)); foreach (Match M in ThisMatch.MatchesFound) { NewText.AppendLine(string.Format("\t{0}", M.Captures[0].ToString())); } } } NewText.AppendLine(Separator); } txtResults.Text = NewText.ToString(); } private List&lt;MatchValue&gt; FindPassages(List&lt;MySpecialStringStruct&gt; PassageList, string WhatToFind) { Regex MatchPattern = new Regex(WhatToFind); List&lt;MatchValue&gt; ReturnValue = new List&lt;MatchValue&gt;(); foreach (MySpecialStringStruct SearchTarget in PassageList) { MatchCollection MatchList = MatchPattern.Matches(SearchTarget.Passage); if (MatchList.Count &gt; 0) { MatchValue FoundMatchResult = new MatchValue(); FoundMatchResult.WhichStringStruct = SearchTarget; FoundMatchResult.MatchesFound = MatchList; ReturnValue.Add(FoundMatchResult); } } return ReturnValue; } } public class MatchValue { public MySpecialStringStruct WhichStringStruct; public MatchCollection MatchesFound; } public struct MySpecialStringStruct { public string Passage; public int Id; public MySpecialStringStruct(string passage, int id) { Passage = passage; Id = id; } } } </code></pre> <p>The output:</p> <pre><code>Now searching ing\b In passage "This is a test passage with a test ending.": ing In passage "This is a second test passage with a test ending.": ing ------------------------------------------ Now searching \bsecond\b In passage "This is a second test passage with a test ending.": second ------------------------------------------ Now searching \bgarbage text\b No Matches Found ------------------------------------------ </code></pre>
 

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