Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't think your regular expression is doing what you think it's doing. The first part is ok, but the second part, <code>\r\s{3}.\S+(.+)</code>, is looking for a carriage return, followed by exactly three whitespace characters, followed by any one character (whitespace or not), followed by any number of non-whitespace characters, followed by any number of characters which you capture.</p> <p>There are a number of issues with this. First of all, not all text has carriage returns (<code>\r</code>) - checking for a newline (<code>\n</code>) instead is much safer. Even if your text does have <code>\r</code>, there's almost certainly going to be a <code>\n</code> afterwards (Windows ends lines with <code>\r\n</code>). The <code>\n</code> might be absorbed into the <code>\s{3}</code>, depending on your data, though.</p> <p>Secondly, <code>+</code> is a greedy operator. That means that the first <code>+</code> in <code>\S+(.+)</code> will match everything it can - in other words, all non-whitespace characters until it reaches a whitespace. Only <em>after</em> finding a whitespace will the <code>(.+)</code> start capturing, and the first character it has will be whitespace. Alternatively, if there is no whitespace left in the string, the <code>\S+</code> will "give back" one character so that the <code>.+</code> has something to match, in which case it will simply be the last character of the string.</p> <p>All things considered, I think you're going to be much better off with something simpler, like this:</p> <pre><code>RegEx.Split(myData, @"(?=\d)").Where(s =&gt; !string.IsNullOrEmpty(s)) </code></pre> <p>That will split your data every time the next character is a number.</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. 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