Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
"hello Gf 2018~2021!"
<nil>

Split

Code Block
package main

import (
    "fmt"
    "github.com/gogf/gf/text/gregex"
)

func main() {
    patternStr := `\d+`
	str := "hello2020gf"
	result := gregex.Split(patternStr, str)
	g.Dump(result)
}

执行后输出

Code Block
["hello","gf"]

Validate

Code Block
package main

import (
    "fmt"
    "github.com/gogf/gf/text/gregex"
)

func main() {
    // Valid match statement
	g.Dump(gregex.Validate(`\d+`))
	// Mismatched statement
	g.Dump(gregex.Validate(`[a-9]\d+`))
}

执行后输出

Code Block
<nil>
{
	Code: "invalid character class range",
	Expr: "a-9",
}