Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>No need for a regular expression here. You can use <a href="http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&amp;l=EN-US&amp;k=k%28SYSTEM.STRING.ISNULLORWHITESPACE%29;k%28TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22%29;k%28DevLang-CSHARP%29&amp;rd=true" rel="nofollow"><code>string.IsNullOrWhitespace()</code></a></p> <p>A regular expression is this:</p> <pre><code>[^ ] </code></pre> <p>What this does is simple: It checks if your string contains anything that is not a space.</p> <p>I adjusted your code slightly by adding <code>match.Success</code> to the output:</p> <pre><code>var strings = new List&lt;string&gt; { "123", "1 3", "12 ", "1 " , " 3", " ", "" }; string r = "[^ ]"; foreach (string s in strings) { Match match = new Regex(r).Match(s); Console.WriteLine(string.Format("string='{0}', regex='{1}', match='{2}', " + "is match={3}", s, r, match.Value, match.Success)); } </code></pre> <p>The result will be:</p> <pre><code>string='123', regex='[^ ]', match='1', is match=True string='1 3', regex='[^ ]', match='1', is match=True string='12 ', regex='[^ ]', match='1', is match=True string='1 ', regex='[^ ]', match='1', is match=True string=' 3', regex='[^ ]', match='3', is match=True string=' ', regex='[^ ]', match='', is match=False string='', regex='[^ ]', match='', is match=False </code></pre> <p>BTW: Instead of <code>new Regex(r).Match(s)</code> you should use <code>Regex.Match(s, r)</code>. This allows the regex engine to cache the pattern.</p>
    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