|
// retoor <retoor@molodetz.nl>
|
|
|
|
import "regex" for Regex, Match
|
|
|
|
var re = Regex.new(",")
|
|
var parts = re.split("a,b,c")
|
|
System.print(parts.count) // expect: 3
|
|
System.print(parts[0]) // expect: a
|
|
System.print(parts[1]) // expect: b
|
|
System.print(parts[2]) // expect: c
|
|
|
|
var re2 = Regex.new(" ")
|
|
var words = re2.split("one two three")
|
|
System.print(words.count) // expect: 3
|
|
System.print(words[0]) // expect: one
|
|
System.print(words[1]) // expect: two
|
|
System.print(words[2]) // expect: three
|
|
|
|
var re3 = Regex.new("notfound")
|
|
var nomatch = re3.split("original string")
|
|
System.print(nomatch.count) // expect: 1
|
|
System.print(nomatch[0]) // expect: original string
|
|
|
|
var re4 = Regex.new(",")
|
|
var consecutive = re4.split("a,,b")
|
|
System.print(consecutive.count) // expect: 3
|
|
System.print(consecutive[0]) // expect: a
|
|
System.print(consecutive[1]) // expect:
|
|
System.print(consecutive[2]) // expect: b
|
|
|
|
var re5 = Regex.new(",")
|
|
var startDelim = re5.split(",a,b")
|
|
System.print(startDelim.count) // expect: 3
|
|
System.print(startDelim[0]) // expect:
|
|
System.print(startDelim[1]) // expect: a
|
|
System.print(startDelim[2]) // expect: b
|
|
|
|
var re6 = Regex.new(",")
|
|
var endDelim = re6.split("a,b,")
|
|
System.print(endDelim.count) // expect: 3
|
|
System.print(endDelim[0]) // expect: a
|
|
System.print(endDelim[1]) // expect: b
|
|
System.print(endDelim[2]) // expect:
|
|
|
|
var re7 = Regex.new("[,;]")
|
|
var multiDelim = re7.split("a,b;c")
|
|
System.print(multiDelim.count) // expect: 3
|
|
System.print(multiDelim[0]) // expect: a
|
|
System.print(multiDelim[1]) // expect: b
|
|
System.print(multiDelim[2]) // expect: c
|
|
|
|
var re8 = Regex.new("-")
|
|
var varDelim = re8.split("a-b-c-d")
|
|
System.print(varDelim.count) // expect: 4
|
|
System.print(varDelim[0]) // expect: a
|
|
System.print(varDelim[1]) // expect: b
|
|
System.print(varDelim[2]) // expect: c
|
|
System.print(varDelim[3]) // expect: d
|
|
|
|
var re9 = Regex.new(":")
|
|
var single = re9.split("onlyone")
|
|
System.print(single.count) // expect: 1
|
|
System.print(single[0]) // expect: onlyone
|