Skip to content

Instantly share code, notes, and snippets.

@zephyrfalcon
Created April 1, 2015 00:00
Show Gist options
  • Save zephyrfalcon/f828d49ee653f3bf686a to your computer and use it in GitHub Desktop.
Save zephyrfalcon/f828d49ee653f3bf686a to your computer and use it in GitHub Desktop.
ooc: Adding split() method to Regexp
import text/Regexp
import structs/ArrayList
extend Regexp {
split: func (s: String) -> ArrayList<String> {
results := ArrayList<String> new()
while (true) {
matchobj := this matches(s)
if (matchobj == null) break
token := matchobj group(0)
cutoff := matchobj groupStart(0) + matchobj groupLength(0)
results add(token)
s = s substring(cutoff)
}
return results
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment