本文整理汇总了Golang中regexp.Regexp.FindAllString方法的典型用法代码示例。如果您正苦于以下问题:Golang Regexp.FindAllString方法的具体用法?Golang Regexp.FindAllString怎么用?Golang Regexp.FindAllString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类regexp.Regexp
的用法示例。
在下文中一共展示了Regexp.FindAllString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: extractIssueArgs
func extractIssueArgs(text string, re *regexp.Regexp) (*github.IssueRequest, error) {
match := re.FindAllString(text, -1)
m := make([]string, len(match))
for i, v := range match {
m[i] = removeQuotes(v)
}
if m == nil || len(m) == 0 {
return nil, &issueError{text}
}
var title, body, assignee *string
title = &m[0]
if len(m) >= 2 {
body = &m[1]
}
if len(m) >= 3 {
assignee = &m[2]
}
issueState := "open"
request := github.IssueRequest{
Title: title,
Body: body,
Labels: nil,
Assignee: assignee,
State: &issueState,
Milestone: nil,
}
return &request, nil
}
示例2: extractAndMatch
func extractAndMatch(lines []string, pattern *regexp.Regexp) chan string {
matchesChan := make(chan string)
go func() {
defer close(matchesChan)
for _, line := range lines {
if len(line) < 1 {
continue
}
matches := pattern.FindAllString(line, -1)
mappings := make(map[string]bool)
for _, match := range matches {
_, ok := mappings[match]
if ok {
continue
}
matchesChan <- match
mappings[match] = true
}
}
}()
return matchesChan
}
示例3: reFindAll
func reFindAll(re *regexp.Regexp) lua.Function {
return func(l *lua.State) int {
s := lua.CheckString(l, 1)
n := lua.CheckInteger(l, 2)
all := re.FindAllString(s, n)
return util.DeepPush(l, all)
}
}
示例4: Tokenize
// Tokenize tokenizes the given string with the delimiter
func Tokenize(str *string, delimiter *regexp.Regexp) []Token {
if delimiter == nil {
// AWK-style (\S+\s*)
tokens, prefixLength := awkTokenizer(str)
return withPrefixLengths(tokens, prefixLength)
}
tokens := delimiter.FindAllString(*str, -1)
return withPrefixLengths(tokens, 0)
}
示例5: ExtractBy
// ExtractBy returns a string.
func (source *Source) ExtractBy(r *regexp.Regexp) string {
results := r.FindAllString(source.line, 1)
if len(results) != 1 {
return ""
}
result := results[0]
source.line = source.line[len(result):]
return result
}
示例6: scan
func scan(re *regexp.Regexp, r io.Reader) {
scanner := bufio.NewScanner(r)
scanner.Split(bufio.ScanWords)
for scanner.Scan() {
word := scanner.Text()
for _, match := range re.FindAllString(word, -1) {
fmt.Println(match)
}
}
}
示例7: grep
func grep(re *regexp.Regexp, name string, r io.Reader) error {
b := bufio.NewReader(r)
c := uint64(0)
for n := uint64(1); ; n++ {
ln, err := fgetln(b)
m := re.FindAllString(ln, -1)
if len(m) > 0 {
if *qflag {
os.Exit(status)
}
if *cflag {
c += uint64(len(m))
}
found = true
}
if !*cflag {
for _, s := range m {
if *nflag {
s = fmt.Sprintf("%d:%s", n, s)
}
if many {
s = fmt.Sprintf("%s:%s", name, s)
}
if strings.IndexFunc(s, isNonPrint) >= 0 {
fmt.Println("Binary file", name, "matches")
return nil
} else {
fmt.Println(s)
}
}
}
if err == io.EOF {
break
}
if err != nil {
return err
}
}
if *cflag {
s := fmt.Sprintf("%d", c)
if many {
s = fmt.Sprintf("%s:%s", name, s)
}
fmt.Println(s)
}
return nil
}
示例8: listObjects
// listObjects returns a list of entries in a bucket
func (r *s3Client) listObjects(bucket, path string, recursive bool) (list []*objectFile, err error) {
log.Debugf("retrieving the secrets from bucket: %s, path: '%s'", bucket, path)
pathBaseDirectory := filepath.Dir(path)
if pathBaseDirectory == "." {
pathBaseDirectory = ""
}
var regex *regexp.Regexp
switch recursive {
case true:
regex, err = regexp.Compile("^" + strings.Replace(path, "*", ".*", 0) + "[\\w-_\\.]*[$/]?.*")
default:
regex, err = regexp.Compile("^" + strings.Replace(path, "*", ".*", 0) + "[\\w-_\\.]*[$/]?")
}
if err != nil {
return list, err
}
resp, err := r.client.ListObjects(&s3.ListObjectsInput{
Bucket: aws.String(bucket),
Prefix: aws.String(pathBaseDirectory),
})
if err != nil {
return list, err
}
seenDir := make(map[string]bool, 0)
for _, object := range resp.Contents {
matches := regex.FindAllString(*object.Key, 1)
if len(matches) <= 0 {
continue
}
entry := &objectFile{path: matches[0]}
if !strings.HasSuffix(entry.path, "/") {
entry.size = *object.Size
entry.lastModified = object.LastModified
entry.owner = *object.Owner.DisplayName
} else {
if found := seenDir[entry.path]; found {
continue
}
seenDir[entry.path] = true
entry.directory = true
}
list = append(list, entry)
}
return list, nil
}
示例9: Parse
// Parse sets a operand value to the register operand and
// returns the remain string and true.
//
// If the source is invalid,
// This returns the source itself and false.
// In this case doesn't change the register operand.
func (operand *Single) Parse(source string, byRegex *regexp.Regexp) (string, bool) {
matches := byRegex.FindAllString(string(source), 1)
if len(matches) <= 0 {
return source, false
}
operand.SingleValue = strings.Trim(matches[0], " \t,")
operand.HasValue = true
remains := byRegex.ReplaceAllString(string(source), "")
if strings.HasSuffix(matches[0], ",") {
remains = "," + remains
}
return remains, true
}
示例10: replaceRegex
func (g *GoltGenerator) replaceRegex(regex *regexp.Regexp, value *string) {
/*
Given a specific regular expression, a pointer to a string and a map of stored variable
This method will have the side effect of changing the value pointer by the string if the regex is matching
*/
if regex.MatchString(*value) {
for _, foundMatch := range regex.FindAllString(*value, -1) {
mapKey := foundMatch[2 : len(foundMatch)-1]
extractedValue := g.RegexMap[mapKey]
*value = strings.Replace(*value, foundMatch, extractedValue, -1)
}
}
}
示例11: fullMatchString
func fullMatchString(re *regexp.Regexp, s string) []string {
var rs = re.FindAllStringIndex(s, -1)
var cur int
for _, r := range rs {
if notWhiteSpace(s, cur, r[0]) {
return nil
}
if cur > 0 && cur == r[0] {
return nil
}
cur = r[1]
}
if notWhiteSpace(s, cur, len(s)) {
return nil
}
return re.FindAllString(s, -1)
}
示例12: readProductType
func readProductType(lines []string, regex *regexp.Regexp) int64 {
for _, line := range lines {
if regex.MatchString(line) {
result := regex.FindAllString(line, 1)
if len(result) > 0 {
productString := result[0]
productId := productString[len(productString)-6:]
product, err := strconv.ParseInt(productId, 0, 32)
if err != nil {
fmt.Println("Error parsing product id", err)
return 0
}
return product
}
return 0
}
}
return 0
}
示例13: scanPath
func scanPath(re *regexp.Regexp, path string) error {
r := os.Stdin
if path != "-" {
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()
r = f
}
scanner := bufio.NewScanner(r)
scanner.Split(bufio.ScanWords)
for scanner.Scan() {
word := scanner.Text()
for _, match := range re.FindAllString(word, -1) {
fmt.Println(match)
}
}
return scanner.Err()
}
示例14: ReadList
// ReadList takes a Matcher list, that is then read and scanned for data.
func ReadList(buf *bufio.Reader, mt Matcher, reg *regexp.Regexp) {
line, err := buf.ReadString('\n')
if err != nil {
panic(fmt.Errorf("Unexpected end of file"))
}
var n int
fmt.Sscanf(line, "%d", &n)
// Reset the list.
mt.CreateList(n)
// Matches all lines and scan in.
for err != io.EOF {
line, err = buf.ReadString('\n')
if err != nil && err != io.EOF {
panic(err)
}
matches := reg.FindAllString(line, -1)
if len(matches) == 4 {
index := -1
fmt.Sscanf(matches[0], "%d", &index)
mt.Match(matches, index)
}
}
}
示例15: bench
func bench(b *testing.B, re *regexp.Regexp, str string) {
for i := 0; i < b.N; i++ {
re.FindAllString(str, -1)
}
}