<commit_before>// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.

package gregex_test

func ExampleIsMatch() {

}

func ExampleIsMatchString() {

}

func ExampleMatch() {

}

func ExampleMatchAll() {

}

func ExampleMatchAllString() {

}

func ExampleMatchString() {

}

func ExampleQuote() {

}

func ExampleReplace() {

}

func ExampleReplaceFunc() {

}

func ExampleReplaceFuncMatch() {

}

func ExampleReplaceString() {

}

func ExampleReplaceStringFunc() {

}

func ExampleReplaceStringFuncMatch() {

}

func ExampleSplit() {

}

func ExampleValidate() {

}<commit_msg>:memo: add example<commit_after>// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gregex_test

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

func ExampleIsMatch() {
	var str = "hello 94 easy gf!"
	patternStr := `[1-9]\d*`
	fmt.Println(gregex.IsMatch(patternStr, []byte(str)))

	// output
	// true
}

func ExampleIsMatchString() {
	var str = "hello 94 easy gf!"
	patternStr := `[1-9]\d*`
	fmt.Println(gregex.IsMatchString(patternStr, str))

	// output
	// true
}

func ExampleMatch() {
	var str = "hello 94 easy gf!"
	patternStr := `[1-9]\d*`
	result, err := gregex.Match(patternStr, []byte(str))
	if err != nil {
		fmt.Println(err.Error())
	}
	for _, v := range result {
		fmt.Println(string(v))
	}

	// output
	// 94
}

func ExampleMatchAll() {
	var str = "hello 94 easy gf!"
	patternStr := `[1-9]\d*`
	results, err := gregex.MatchAll(patternStr, []byte(str))
	if err != nil {
		fmt.Println(err.Error())
	}
	for _, result := range results {
		for _, v := range result {
			fmt.Println(string(v))
		}
	}

	// output
	// 94
}

func ExampleMatchAllString() {
	var str = "hello 94 easy gf!"
	patternStr := `[1-9]\d*`
	results, err := gregex.MatchAllString(patternStr, str)
	if err != nil {
		fmt.Println(err.Error())
	}
	for _, result := range results {
		for _, v := range result {
			fmt.Println(v)
		}
	}

	// output
	// 94
}

func ExampleMatchString() {
	var str = "hello 94 easy gf!"
	patternStr := `[1-9]\d*`
	results, err := gregex.MatchString(patternStr, str)
	if err != nil {
		fmt.Println(err.Error())
	}
	for _, result := range results {
		fmt.Println(result)
	}

	// output
	// 94
}

func ExampleQuote() {
	patternStr := `[1-9]\d*`
	result := gregex.Quote(patternStr)
	fmt.Println(result)

	// output
	// \[1-9\]\\d\*
}

func ExampleReplace() {
	patternStr := `[1-9]\d*`
	str := "hello gf 2020!"
	repStr := "2021"
	result, err := gregex.Replace(patternStr, []byte(repStr), []byte(str))
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Println(string(result))

	// output
	// hello gf 2021!
}

func ExampleReplaceFunc() {
	patternStr := `[1-9]\d*`
	str := "hello gf 2020!"
	result, err := gregex.ReplaceFunc(patternStr, []byte(str), func(b []byte) []byte {
		replaceStr := "2021"
		if string(b) == "2020" {
			return []byte(replaceStr)
		}
		return nil
	})
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Println(string(result))

	// output
	// hello gf 2021!
}

func ExampleReplaceFuncMatch() {
	patternStr := `[1-9]\d*`
	str := "hello gf 2020!"
	result, err := gregex.ReplaceFuncMatch(patternStr, []byte(str), func(match [][]byte) []byte {
		replaceStr := "2021"
		for _, v := range match {
			if string(v) == "2020" {
				return []byte(replaceStr)
			}
		}
		return nil
	})
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Println(string(result))

	// output
	// hello gf 2021!
}

func ExampleReplaceString() {
	patternStr := `[1-9]\d*`
	str := "hello gf 2020!"
	replaceStr := "2021"
	result, err := gregex.ReplaceString(patternStr, replaceStr, str)
	if err != nil {
		fmt.Println(result)
	}
	fmt.Println(result)

	// output
	// hello gf 2021!
}

func ExampleReplaceStringFunc() {
	patternStr := `[1-9]\d*`
	str := "hello gf 2020!"
	result, err := gregex.ReplaceStringFunc(patternStr, str, func(s string) string {
		replaceStr := "2021"
		if s == "2020" {
			return replaceStr
		}
		return ""
	})
	if err != nil {
		fmt.Println(result)
	}
	fmt.Println(result)

	// output
	// hello gf 2021!
}

func ExampleReplaceStringFuncMatch() {
	patternStr := `[1-9]\d*`
	str := "hello gf 2020!"
	result, err := gregex.ReplaceStringFuncMatch(patternStr, str, func(match []string) string {
		replaceStr := "2021"
		for _, v := range match {
			if v == "2020" {
				return replaceStr
			}
		}
		return ""
	})
	if err != nil {
		fmt.Println(result)
	}
	fmt.Println(result)

	// output
	// hello gf 2021!
}

func ExampleSplit() {
	patternStr := `[1-9]\d*`
	str := "hello2020gf"
	result := gregex.Split(patternStr, str)
	for _, v := range result {
		fmt.Println(v)
	}

	// output
	// hello
	// gf
}

func ExampleValidate() {
	patternStr := `[1-9]\d*`
	err := gregex.Validate(patternStr)
	if err != nil {
		fmt.Println(err)
	}
	if err == nil {
		fmt.Println("ok")
	}

	// output
	// ok
}
{'fraction_non_alphanumeric': 0.17096649980747017, 'fraction_numerical': 0.027916827108201772, 'mean_word_length': 3.318370739817124, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1868384', 'n_tokens_mistral': 2151, 'n_tokens_neox': 1970, 'n_words': 479}