Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First script: The first result is the whole pattern, the second is the capturing group</p> <p>Second script: the only result is the whole pattern.</p> <p>Capturing groups are not only to refer later in the pattern, they are displayed in results too.</p> <p>When you use a capturing group with split, the capturing group is returned with results and since the separator is supposed to slice the string, it is normal that you obtain <code>["", " ", ""]</code> as result with <br><code>" "</code> as input string and <code>/(\s)/</code> as pattern.</p> <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split" rel="nofollow">More informations about split.</a></p> <p>When you write <code>" ".match(/(\s)/)</code> the result returned is the first match. This result is unique and contains:</p> <ul> <li>the whole match</li> <li>capturing group(s)</li> <li>index of the match</li> <li>input string</li> </ul> <p>When you write <code>" ".match(/(\s)/g)</code> the result returned is all the matches:</p> <ul> <li>whole match 1</li> <li>whole match 2</li> <li>etc.</li> </ul> <p>(in the present case you have only one match)</p> <p>This behaviour is normal. The match method as two different behaviours (with or without <code>/g</code>). It is a kind of two functions in one. For comparison in PHP (or other languages) which doesn't have the <code>g</code> modifier, you have two different functions: <code>preg_match</code> and <code>preg_match_all</code></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