node_regexp.go 558 B

1234567891011121314151617
  1. package core
  2. import (
  3. "regexp"
  4. "github.com/dop251/goja"
  5. )
  6. func Regexp(call goja.ConstructorCall) *goja.Object {
  7. pattern := call.Arguments[0].String()
  8. call.This.Set("find", regexp.MustCompile(pattern).FindString)
  9. call.This.Set("findSubmatch", regexp.MustCompile(pattern).FindStringSubmatch)
  10. call.This.Set("findAll", regexp.MustCompile(pattern).FindAllString)
  11. call.This.Set("findAllSubmatch", regexp.MustCompile(pattern).FindAllStringSubmatch)
  12. call.This.Set("replaceAll", regexp.MustCompile(pattern).ReplaceAllString)
  13. return nil
  14. }