|
// retoor <retoor@molodetz.nl>
|
|
|
|
import "regex" for Regex, Match
|
|
|
|
var re = Regex.new("\\d+")
|
|
var matches = re.matchAll("abc123def")
|
|
|
|
System.print(matches.count) // expect: 1
|
|
System.print(matches[0].text) // expect: 123
|
|
System.print(matches[0].start) // expect: 3
|
|
System.print(matches[0].end) // expect: 6
|
|
|
|
var re2 = Regex.new("notfound")
|
|
var empty = re2.matchAll("some text")
|
|
System.print(empty.count) // expect: 0
|
|
|
|
var re3 = Regex.new("(\\w+)@(\\w+)")
|
|
var emails = re3.matchAll("contact: user@domain here")
|
|
System.print(emails.count) // expect: 1
|
|
System.print(emails[0].text) // expect: user@domain
|
|
System.print(emails[0][1]) // expect: user
|
|
System.print(emails[0][2]) // expect: domain
|
|
|
|
var re4 = Regex.new("a")
|
|
var manyA = re4.matchAll("apple")
|
|
System.print(manyA.count) // expect: 1
|
|
System.print(manyA[0].start) // expect: 0
|
|
|
|
var re5 = Regex.new("test")
|
|
var single = re5.matchAll("this is a test string")
|
|
System.print(single.count) // expect: 1
|
|
System.print(single[0].text) // expect: test
|
|
System.print(single[0].start) // expect: 10
|
|
System.print(single[0].end) // expect: 14
|
|
|
|
var re6 = Regex.new(" ")
|
|
var spaces = re6.matchAll("a b")
|
|
System.print(spaces.count) // expect: 1
|
|
System.print(spaces[0].text == " ") // expect: true
|
|
System.print(spaces[0].start) // expect: 1
|