Javascript regexp with unicode and punctuation
<p>I have the follow test case for splitting unicoded words but don't know how to do in it javascript.</p>

<pre><code>describe("garden: utils", () =&gt; {
  it("should split correctly", () =&gt; {
    assert.deepEqual(segmentation('Hockey is a popular sport in Canada.'), [
      'Hockey', 'is', 'a', 'popular', 'sport', 'in', 'Canada', '.'
    ]);

    assert.deepEqual(segmentation('How many provinces are there in Canada?'), [
      'How', 'many', 'provinces', 'are', 'there', 'in', 'Canada', '?'
    ]);

    assert.deepEqual(segmentation('The forest is on fire!'), [
      'The', 'forest', 'is', 'on', 'fire', '!'
    ]);

    assert.deepEqual(segmentation('Emily Carr, who was born in 1871, was a great painter.'), [
      'Emily', 'Carr', ',', 'who', 'was', 'born', 'in', '1871', ',', 'was', 'a', 'great', 'painter', '.'
    ]);

    assert.deepEqual(segmentation('This is David\'s computer.'), [
      'This', 'is', 'David', '\'', 's', 'computer', '.'
    ]);

    assert.deepEqual(segmentation('The prime minister said, "We will win the election."'), [
      'The', 'prime', 'minister', 'said', ',', '"', 'We', 'will', 'win', 'the', 'election', '.', '"'
    ]);

    assert.deepEqual(segmentation('There are three positions in hockey: goalie, defence, and forward.'), [
      'There', 'are', 'three', 'positions', 'in', 'hockey', ':', 'goalie', ',', 'defence', ',', 'and', 'forward', '.'
    ]);

    assert.deepEqual(segmentation('The festival is very popular; people from all over the world visit each year.'), [
      'The', 'festival', 'is', 'very', 'popular', ';', 'people', 'from', 'all', 'over', 'the', 'world',
      'visit', 'each', 'year', '.'
    ]);

    assert.deepEqual(segmentation('Mild, wet, and cloudy - these are the characteristics of weather in Vancouver.'), [
      'Mild', ',', 'wet', ',', 'and', 'cloudy', '-', 'these', 'are', 'the', 'characteristics', 'of', 'weather',
      'in', 'Vancouver', '.'
    ]);

    assert.deepEqual(segmentation('sweet-smelling'), [
      'sweet', '-', 'smelling'
    ]);
  });

  it("should not split unicoded words", () =&gt; {
    assert.deepEqual(segmentation('hacer a propÃ³sito'), [
      'hacer', 'a', 'propÃ³sito'
    ]);

    assert.deepEqual(segmentation('nhÃ  em cÃ³ con mÃ¨o'), [
      'nhÃ ', 'em', 'cÃ³', 'con', 'mÃ¨o'
    ]);
  });

  it("should group periods", () =&gt; {
    assert.deepEqual(segmentation('So are ... the fishes.'), [
      'So', 'are', '...', 'the', 'fishes', '.'
    ]);

    assert.deepEqual(segmentation('So are ...... the fishes.'), [
      'So', 'are', '......', 'the', 'fishes', '.'
    ]);

    assert.deepEqual(segmentation('arriba arriba ja....'), [
      'arriba', 'arriba', 'ja', '....'
    ]);
  });
});
</code></pre>

<p>Here is the equivalent expression in python:</p>

<pre><code>class Segmentation(BaseNLPProcessor):
    pattern = re.compile('((?u)\w+|\.{2,}|[%s])' % string.punctuation)

    @classmethod
    def ignore_value(cls, value):
        # type: (str) -&gt; bool
        return negate(compose(is_empty, string.strip))(value)

    def split(self):
        # type: () -&gt; List[str]
        return filter(self.ignore_value, self.pattern.split(self.value()))
</code></pre>

<p>I want to write a equivalent function in python for javascript to split by unicoded words and punctuation, group by multiple dots ...</p>

<pre><code>Segmentation("Hockey is a popular sport in Canada.").split()
</code></pre>

<p>I found the answer but is is complex. Does anyone have another simple answer for this</p>

<pre><code>module.exports = (string) =&gt; {
  const segs = string.split(/(\.{2,}|!|"|#|$|%|&amp;|'|\(|\)|\*|\+|,|-|\.|\/|:|;|&lt;|=|&gt;|\?|Â¿|@|[|]|\\|^|_|`|{|\||}|~| )/);

  return segs.filter((seg) =&gt; seg.trim() !== "");
};
</code></pre>

javascript python regex unicode punctuation