Multisplit: Difference between revisions

m
wordliness
m (wordliness and added requirement for whole string minus first character)
m (wordliness)
Line 1:
{{draft task}}It is often necessary to split a string into pieces based on several different (potentially multi-character) separator strings, while still retaining the information about which separators were present in the input. This is particularly useful when doing small parsing tasks. The task is to write code to demonstrate this.
 
The function (or procedure or method, as appropriate) should take an input string and an ordered collection of separators. The order of the separators is significant: The delimiter order represents priority in matching., Thewith the first defined delimiter hashaving the highest priority,. In socases where there would be an ambiguity as to which separator to use at a particular point (e.g., because one separator is a prefix of another) the first separator inwith the collectionhighest priority should be used. Delimiters can be reused. Theand the output from the function should be an ordered sequence of substrings.
 
Test your code using the input string “<code>a!===b=!=c</code>” and the separators “<code>==</code>”, “<code>!=</code>” and “<code>=</code>”.