Multisplit: Difference between revisions

Added Wren
m (→‎{{header|Factor}}: A small optimization in best-separator: no need to filter if we only need to take the first element of the result, might as well just find the first matching one.)
(Added Wren)
Line 2,041:
Standard: a,,b,,c
Extra Credit: a(!=)(==)b(=)(!=)c
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-pattern}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/pattern" for Pattern
import "/fmt" for Fmt
 
var input = "a!===b=!=c"
var p = Pattern.new("[/=/=|!/=|/=]")
var separators = p.findAll(input)
System.print("The separators matched and their starting/ending indices are:")
for (sep in separators) {
System.print(" %(Fmt.s(-4, Fmt.q(sep.text))) between %(sep.span)")
}
var parts = p.splitAll(input)
System.print("\nThe substrings between the separators are:")
System.print(parts.map { |p| (p != "") ? Fmt.q(p) : "empty string" }.toList)</lang>
 
{{out}}
<pre>
The separators matched and their starting/ending indices are:
"!=" between [1, 2]
"==" between [3, 4]
"=" between [6, 6]
"!=" between [7, 8]
 
The substrings between the separators are:
["a", empty string, "b", empty string, "c"]
</pre>
 
9,486

edits