当前位置: 首页>>代码示例>>Golang>>正文


Golang Regexp.FindAllString方法代码示例

本文整理汇总了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
}
开发者ID:ajm188,项目名称:slack,代码行数:28,代码来源:github.go

示例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
}
开发者ID:odeke-em,项目名称:vidler,代码行数:28,代码来源:entrail.go

示例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)
	}
}
开发者ID:telemetryapp,项目名称:goluago,代码行数:8,代码来源:regexp.go

示例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)
}
开发者ID:zennro,项目名称:fzf,代码行数:10,代码来源:tokenizer.go

示例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
}
开发者ID:mm0205,项目名称:gcasl,代码行数:10,代码来源:source.go

示例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)
		}
	}
}
开发者ID:digideskio,项目名称:xurls,代码行数:10,代码来源:main.go

示例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
}
开发者ID:qeedquan,项目名称:misc_utilities,代码行数:54,代码来源:tinygrep.go

示例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
}
开发者ID:lucmichalski,项目名称:s3secrets,代码行数:55,代码来源:s3.go

示例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
}
开发者ID:mm0205,项目名称:gcasl,代码行数:19,代码来源:single.go

示例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)
		}
	}
}
开发者ID:dudang,项目名称:golt,代码行数:13,代码来源:generator.go

示例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)
}
开发者ID:tradia,项目名称:gotable,代码行数:19,代码来源:main.go

示例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
}
开发者ID:icecreammatt,项目名称:gopherwink,代码行数:19,代码来源:utils.go

示例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()
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:20,代码来源:main.go

示例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)
		}
	}
}
开发者ID:Nvveen,项目名称:Revolution,代码行数:24,代码来源:main.go

示例15: bench

func bench(b *testing.B, re *regexp.Regexp, str string) {
	for i := 0; i < b.N; i++ {
		re.FindAllString(str, -1)
	}
}
开发者ID:digideskio,项目名称:xurls,代码行数:5,代码来源:xurls_test.go


注:本文中的regexp.Regexp.FindAllString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。