|
// retoor <retoor@molodetz.nl>
|
|
|
|
import "regex" for Regex, Match
|
|
|
|
var re = Regex.new("(\\w+)@(\\w+)")
|
|
var m = re.match("email: user@domain here")
|
|
|
|
System.print(m.text) // expect: user@domain
|
|
System.print(m.start) // expect: 7
|
|
System.print(m.end) // expect: 18
|
|
System.print(m.toString) // expect: user@domain
|
|
|
|
System.print(m.groups.count) // expect: 3
|
|
System.print(m.groups[0]) // expect: user@domain
|
|
System.print(m.groups[1]) // expect: user
|
|
System.print(m.groups[2]) // expect: domain
|
|
|
|
System.print(m.group(0)) // expect: user@domain
|
|
System.print(m.group(1)) // expect: user
|
|
System.print(m.group(2)) // expect: domain
|
|
|
|
System.print(m[0]) // expect: user@domain
|
|
System.print(m[1]) // expect: user
|
|
System.print(m[2]) // expect: domain
|
|
|
|
System.print(m.group(100) == null) // expect: true
|
|
System.print(m.group(-1) == null) // expect: true
|
|
System.print(m[-1] == null) // expect: true
|
|
System.print(m[999] == null) // expect: true
|
|
|
|
var re2 = Regex.new("test")
|
|
var m2 = re2.match("a test string")
|
|
System.print(m2.start) // expect: 2
|
|
System.print(m2.end) // expect: 6
|
|
System.print(m2.text) // expect: test
|
|
|
|
var re3 = Regex.new("^start")
|
|
var m3 = re3.match("start of string")
|
|
System.print(m3.start) // expect: 0
|
|
System.print(m3.end) // expect: 5
|
|
|
|
var re4 = Regex.new("end$")
|
|
var m4 = re4.match("the end")
|
|
System.print(m4.start) // expect: 4
|
|
System.print(m4.end) // expect: 7
|
|
|
|
var re5 = Regex.new("notfound")
|
|
var m5 = re5.match("some text")
|
|
System.print(m5 == null) // expect: true
|