Exemple #1
0
func (self *Regex) Matches(s string) []string {
	res := new(vector.StringVector)
	self.l.StartString(s)
	for !self.l.Eof() {
		if self.l.Next() == 0 {
			res.Push(self.l.String())
		}
	}
	return []string(*res.Slice(0, res.Len()))
}
Exemple #2
0
func (self *Regex) Replace(s string, f func(string) string) string {
	res := new(vector.StringVector)
	buf := bytes.Runes([]byte(s))
	last := 0
	self.l.StartString(s)
	for !self.l.Eof() {
		if self.l.Next() == 0 {
			res.Push(string(buf[last:self.l.Pos()]))
			res.Push(f(self.l.String()))
			last = self.l.Pos() + self.l.Len()
		}
	}
	res.Push(string(buf[last:]))
	return strings.Join([]string(*res.Slice(0, res.Len())), "")
}