Regular expressions · 12 / 15 Exercise Medium

Split by several separators

Objective

Create a Python program that splits a text that uses different separators with re.split.

Instructions

  • Read a line with elements separated by commas, semicolons or spaces, or by a mix of them with any number of repetitions. The text neither starts nor ends with a separator.
  • Split it with re.split(r"[,;\s]+", text).
  • On the first line show Items: N, with the number of items.
  • On the second line show the items joined with the | character.
Input
a,b;c d
Output
Items: 4
a|b|c|d

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise