Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>\S\s\S\s\S</code> will indeed match three non-space characters separated by space characters. However, <code>^.*?[\S\s\S\s\S].{5}</code> does something completely different:</p> <ul> <li><code>^</code> matches the beginning of the line.</li> <li><code>.*?</code> matches characters until the next match can start (<em>not</em> as many as it can). Since you specify <code>/s</code>, <code>.</code> will match newline as well.</li> <li><code>[\S\s\S\s\S]</code> is a character class, and so is the same as <code>[\S\s]</code>—match either <code>\S</code> or <code>\s</code>, which is to say anything.</li> <li><code>.{5}</code> will match five characters.</li> </ul> <p>Since <code>[\S\s]</code> and <code>.</code> with <code>/s</code> match the same things, the <code>.*?</code> will never match any characters as it wants to match as little as possible. Thus, this is the same as <code>s/^.{6}//s</code>—delete the first six characters from the string. As you can see, that's not what you wanted!</p> <p>One way to keep the first three numbers is to explicitly match them: <code>s/^(\d \d \d).*/$1/s</code>. Here, <code>\d</code> matches a single digit (<code>0</code>–<code>9</code>) with literal spaces in between them. We match the first three followed by anything at all, and then replace the whole match—since it ends in <code>.*</code>, that's the whole string—with just the bit in between parentheses, <em>i.e.</em> the first three numbers. If your numbers can be more than one digit long, then <code>s/^(\d+ \d+ \d+).*/$1/s</code> will do what you want; if you can have arbitrary space-like characters (space, tab, newline) separating them, then <code>s/^(\d\s\d\s\d\s).*/$1/s</code> is what you want (or <code>\s+</code> if you can have multiple spaces). If you want to catch lines which have things other than digits, you can use <code>\S</code> or <code>\S+</code>, just as you were.</p> <p>Another approach, using lookbehind, would be <code>s/(?&lt;=^\d \d \d).*//s</code>. In other words, delete any characters which are preceded by <code>^\d \d \d</code>—the beginning of the string followed by three space-separated numbers. There's no real advantage to this approach—I'd probably do it the other way—but since you mentioned lookbehind, here's how you can do it. (Again, things like <code>s/(?&lt;=^\S\s\S\s\S).*//s</code> are more general.)</p>
    singulars
    1. This table or related slice is empty.
    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