title: str.match(reg) equivalent for str.split(".") in javascript
body: <p>Is there a regular expression <code>reg</code>, so that for any string <code>str</code> the results of <code>str.split(".")</code> and <code>str.match(reg)</code> are equivalent? If multiline should somehow matter, a solution for a single line would be sufficient.</p>
  
  <p>As an example: Considering the RegExp <code>/[^\.]+/g</code>: for the string <code>"nice.sentance"</code>, <code>"nice.sentance".split(".")</code> gives the same result as <code>"nice.sentance".match(/[^\.]+/g)</code> - <code>["nice", "sentance"]</code>. However, this is not the case for any string. E.g. for the empty string <code>""</code> they would give different results, <code>"".split(".")</code> returning <code>[""]</code> and <code>"".match(/[^\.]+/g)</code> returning <code>null</code>, meaning <code>/[^\.]+/g</code> is not a solution, as it would need to work for any possible string.</p>
  
  <p>The question comes from a misinterpretation of another question here and left me wondering. I do not have a practical application for it at the moment and am interested because i could not find an answer - it looks like an interesting RegExp problem. It may however be impossible.</p>
  
  <p>Things i have considered:</p>
  
  <ul>
  <li><p>Imho it is fairly clear that <code>reg</code> needs the global flag, removing capture groups as a possibility</p></li>
  <li><p><code>/[^\.]+/g</code> does not match empty parts, e.g. for <code>""</code>, <code>".a"</code> or <code>"a..a"</code></p></li>
  <li><p><code>/[^\.]*/g</code> produces additional empty strings after non-empty matches, because when iteration starts for the next match, it can fit in an empty match. E.g. for <code>"a"</code></p></li>
  <li><p>With features not available on javascript <a href="https://github.com/tc39/proposal-regexp-lookbehind" rel="nofollow noreferrer">currently</a> (but on other languages), one could repair the previous flaw: <code>/(?&lt;=^|\.)[^\.]*/g</code></p></li>
  </ul>
  
  <p>My conclusion here would be that real empty matches need to be considered but cannot be differentiated from empty matches between a non-empty match and the following dot or EOL, without "looking behind". This seems a bit vague to count as a proper argument for it being impossible, but maybe is already enough. There might however be a RegExp feature i don't know about, e.g. to advance the index after a match without including the symbol, or something similar to be used as a trick.</p>
  
  <p>Allowing some correction step on the array resulting from <code>match</code> makes the problem trivial.</p>
  
  <hr>
  
  <p>I found some related questions, which as expected utilize look-behind or capture groups though:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/1454913/regular-expression-to-find-a-string-included-between-two-characters-while-exclud">Regular Expression to find a string included between two characters while EXCLUDING the delimiters</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/11132627/characters-between-two-delimiters">characters between two delimiters</a></p></li>
  <li><p>lots more similar to the above</p></li>
  </ul>