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


Golang Regexp.FindAllStringSubmatch方法代码示例

本文整理汇总了Golang中regexp.Regexp.FindAllStringSubmatch方法的典型用法代码示例。如果您正苦于以下问题:Golang Regexp.FindAllStringSubmatch方法的具体用法?Golang Regexp.FindAllStringSubmatch怎么用?Golang Regexp.FindAllStringSubmatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在regexp.Regexp的用法示例。


在下文中一共展示了Regexp.FindAllStringSubmatch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: logFilenameToTime

func logFilenameToTime(filename string, filenameToTimeRegex *regexp.Regexp) (time.Time, error) {
	if filenameToTimeRegex == nil {
		return time.Now(), fmt.Errorf("filename_to_time_regex is not set in indexer configuration")
	}
	n1 := filenameToTimeRegex.SubexpNames()
	r2s := filenameToTimeRegex.FindAllStringSubmatch(filename, -1)
	if len(r2s) == 0 {
		return time.Now(), fmt.Errorf("filename_to_time_regex did not match %q", filename)
	}
	r2 := r2s[0]

	md := map[string]string{}
	for i, n := range r2 {
		md[n1[i]] = n
	}

	getOrZero := func(key string) int {
		val, exists := md[key]
		if !exists {
			return 0
		}
		num, err := strconv.Atoi(val)
		if err != nil {
			return 0
		}
		return num
	}
	year := getOrZero("year")
	month := time.Month(getOrZero("month"))
	day := getOrZero("day")
	hour := getOrZero("hour")
	minute := getOrZero("minute")
	return time.Date(year, month, day, hour, minute, 0, 0, time.UTC), nil
}
开发者ID:JustinAzoff,项目名称:flow-indexer,代码行数:34,代码来源:util.go

示例2: parseEntries

// parseEntries parses ENTRY elements.
func (a *AsxParser) parseEntries(entries [][]string) {

	// Regular expression to match stream URL
	var urlr *regexp.Regexp
	var s *Stream

	// Go over all found entries
	for idx, entry := range entries {

		s = NewStream(idx)

		// First we parse all the info we can get except the URL to a stream
		for _, reg := range asxRegs {

			// We do this one last
			if reg.name == "Url" {
				urlr = reg.reg
				continue
			}

			values := reg.reg.FindStringSubmatch(entry[1])

			var value string

			if len(values) == 2 {
				value = values[1]
			} else {
				value = a.getValue(reg.name)
			}

			s.setValue(reg.name, value)
		}

		// Inherit base for URLs from main playlist body
		if s.Base != "" {
			s.Base = a.Base
		}

		// Make sure the base ends with "/"
		if s.Base != "" && !strings.HasSuffix(s.Base, "/") {
			s.Base += "/"
		}

		// Find all the stream URLs
		streams := urlr.FindAllStringSubmatch(entry[1], -1)

		for _, stream := range streams {

			newStream := s.makeCopy()

			// Prefix base URL to the stream URL
			if newStream.Base != "" {
				stream[1] = newStream.Base + stream[1]
			}

			newStream.Url = stream[1]
			a.Streams = append(a.Streams, newStream)
		}
	}
}
开发者ID:rzajac,项目名称:plparser,代码行数:61,代码来源:asxparser.go

示例3: handleMessage

//broker.handleMessage() gets messages from broker.This() and handles them according
// to the user-provided plugins currently loaded.
func (b *Broker) handleMessage(thingy map[string]interface{}) {
	if b.cbIndex[M] == nil {
		return
	}
	message := new(Event)
	jthingy, _ := json.Marshal(thingy)
	json.Unmarshal(jthingy, message)
	message.Broker = b
	botNamePat := fmt.Sprintf(`^(?:@?%s[:,]?)\s+(?:${1})`, b.Config.Name)
	for _, cbInterface := range b.cbIndex[M] {
		callback := cbInterface.(*MessageCallback)

		Logger.Debug(`Broker:: checking callback: `, callback.ID)
		if callback.SlackChan != `` {
			if callback.SlackChan != message.Channel {
				Logger.Debug(`Broker:: dropping message because chan mismatch: `, callback.ID)
				continue //skip this message because it doesn't match the cb's channel filter
			} else {
				Logger.Debug(`Broker:: channel filter match for: `, callback.ID)
			}
		}
		var r *regexp.Regexp
		if callback.Respond {
			r = regexp.MustCompile(strings.Replace(botNamePat, "${1}", callback.Pattern, 1))
		} else {
			r = regexp.MustCompile(callback.Pattern)
		}
		if r.MatchString(message.Text) {
			match := r.FindAllStringSubmatch(message.Text, -1)[0]
			Logger.Debug(`Broker:: firing callback: `, callback.ID)
			callback.Chan <- PatternMatch{Event: message, Match: match}
		}
	}
}
开发者ID:ivanfoo,项目名称:lazlo,代码行数:36,代码来源:broker.go

示例4: GetDeps

func GetDeps(data []byte, dependRegex *regexp.Regexp) []string {
	var deps = []string{}
	for _, m := range dependRegex.FindAllStringSubmatch(string(data), -1) {
		deps = append(deps, m[regexFilepathGroupIndex])
	}
	return deps
}
开发者ID:buildfx,项目名称:build.fx,代码行数:7,代码来源:buildfx.go

示例5: ServeHTTP

// Dispatch all registered routes
func (self App) ServeHTTP(res http.ResponseWriter, req *http.Request) {
	ctx := &Context{Req: req, Res: res}
	current_path := regexp.MustCompile(`/+`).ReplaceAllString("/"+strings.TrimSpace(req.URL.Path)+"/", "/")
	current_method := req.Method
	current_host := strings.TrimSpace(strings.ToLower(strings.SplitN(req.Host, ":", 2)[0]))
	rlen := len(self.routes)
	var _route route
	var re_vhost, re_path *regexp.Regexp
	var i int
	for i = 0; i < rlen; i++ {
		_route = self.routes[i]
		if !regexp.MustCompile("^" + _route.method + "$").MatchString(current_method) {
			continue
		}
		re_vhost = regexp.MustCompile("^" + _route.vhost + "$")
		if !re_vhost.MatchString(current_host) {
			continue
		}
		re_path = regexp.MustCompile("^" + _route.path + "$")
		if !re_path.MatchString(current_path) {
			continue
		}
		ctx.Params = append(re_vhost.FindAllStringSubmatch(current_host, -1)[0][1:], re_path.FindAllStringSubmatch(current_path, -1)[0][1:]...)
		if !_route.cb(ctx) {
			break
		}
	}
}
开发者ID:leobcn,项目名称:olive-go,代码行数:29,代码来源:olive.go

示例6: normalizeID

// normalizeID returns an ID without the extra formatting that slack might add.
//
// This returns the first captured field of the first submatch using the given
// precompiled regexp. If no matches are found or no captured groups are
// defined then this returns the input text unchanged.
func normalizeID(id string, exp *regexp.Regexp) string {
	idArr := exp.FindAllStringSubmatch(id, 1)
	if len(idArr) == 0 || len(idArr[0]) < 2 {
		return id
	}
	return idArr[0][1]
}
开发者ID:ereyes01,项目名称:victor,代码行数:12,代码来源:slackRealtime.go

示例7: reFindAllSubmatch

func reFindAllSubmatch(re *regexp.Regexp) lua.Function {
	return func(l *lua.State) int {
		s := lua.CheckString(l, 1)
		n := lua.CheckInteger(l, 2)
		allSubmatch := re.FindAllStringSubmatch(s, n)
		return util.DeepPush(l, allSubmatch)
	}
}
开发者ID:telemetryapp,项目名称:goluago,代码行数:8,代码来源:regexp.go

示例8: parseAsx

// parseAsx parses ENTRY nodes in the ASX playlist.
func (s *Stream) parseAsx(asxp *AsxParser) []*Stream {

	// Regular expression to match stream URL
	var urlr *regexp.Regexp

	// First we parse all the info we can get except
	// the URL to a stream
	for _, reg := range asxRegs {

		// We do this one last
		if reg.name == "Url" {
			urlr = reg.reg
			continue
		}

		values := reg.reg.FindStringSubmatch(s.raw)

		var value string

		if len(values) == 2 {
			value = values[1]
		} else {
			value = asxp.getValue(reg.name)
		}

		s.setValue(reg.name, value)
	}

	// Inherit base for URLs from main playlist body
	if s.Base != "" {
		s.Base = asxp.Base
	}

	// Make sure the base ends with "/"
	if s.Base != "" && !strings.HasSuffix(s.Base, "/") {
		s.Base += "/"
	}

	// Find all the stream URLs
	streams := urlr.FindAllStringSubmatch(s.raw, -1)

	var streamsToAdd []*Stream = make([]*Stream, 0, 10)

	for _, stream := range streams {

		newStream := s.makeCopy()

		// Prefix base URL to the stream URL
		if newStream.Base != "" {
			stream[1] = newStream.Base + stream[1]
		}

		newStream.Url = stream[1]
		streamsToAdd = append(streamsToAdd, newStream)
	}

	return streamsToAdd
}
开发者ID:rzajac,项目名称:plparser,代码行数:59,代码来源:asxparser.go

示例9: getMatchesAsMap

func getMatchesAsMap(r *regexp.Regexp, s string) map[string]string {
	matches := r.FindAllStringSubmatch(s, -1)[0]
	names := projectRegexId.SubexpNames()
	md := map[string]string{}
	for i, n := range matches {
		md[names[i]] = n
	}
	return md
}
开发者ID:saaadhu,项目名称:pandora,代码行数:9,代码来源:solution.go

示例10: getMatch

func getMatch(re *regexp.Regexp, matchee *string) (match [][]string, err error) {
	match = nil
	match = re.FindAllStringSubmatch(*matchee, -1)
	if len(match) < 1 {
		err = errors.New("Could not match")
		log.Println(*matchee)
		return
	}
	return
}
开发者ID:jcline,项目名称:goto,代码行数:10,代码来源:plugin.go

示例11: listener

func (b *Brain) listener(pattern *regexp.Regexp, f ListenerFunc) ListenerFunc {
	return func(m adapter.Message) {
		results := pattern.FindAllStringSubmatch(m.Body(), -1)

		if len(results) > 0 {
			m.SetParams(results[0][1:])
			log.Printf("MATCH=%s PARAMS=%s\n", pattern, m.Params())
			f(m)
		}
	}
}
开发者ID:kvangork,项目名称:victor,代码行数:11,代码来源:brain.go

示例12: Params

func Params(url string, regex *regexp.Regexp, keys []string) URLParams {
	match := regex.FindAllStringSubmatch(url, -1)[0][1:]
	result := make(URLParams)
	for i := range match {
		if len(keys) <= i {
			break
		}
		result[keys[i]] = match[i]
	}
	return result
}
开发者ID:SHMEDIALIMITED,项目名称:server,代码行数:11,代码来源:helpers.go

示例13: getKeywordArguments

// getKeywordArguments is called by the base handler to extract keyword arguments from a URL pattern.
func getKeywordArguments(path string, pattern *regexp.Regexp) (args URLArgs) {
	args = make(URLArgs)
	matches := pattern.FindAllStringSubmatch(path, -1)
	for i, key := range pattern.SubexpNames() {
		if i == 0 || key == "" {
			continue
		}
		args[key] = matches[0][i]
	}
	return args
}
开发者ID:arbuckle,项目名称:gofw,代码行数:12,代码来源:urls.go

示例14: FindFirstParenStrings

// FindFirstParenStrings returns slice of first paren
func FindFirstParenStrings(r *regexp.Regexp, s string) []string {
	captures := []string{}
	match := r.FindAllStringSubmatch(s, -1)
	if match == nil {
		return captures
	}
	for i := 0; i < len(match); i++ {
		captures = append(captures, match[i][1])
	}
	return captures
}
开发者ID:get3w,项目名称:get3w,代码行数:12,代码来源:string.go

示例15: checkLine

func checkLine(s string, r1 *regexp.Regexp, r2 *regexp.Regexp) {
	if r1.MatchString(s) {
		fmt.Println(s)
		res := r2.FindAllStringSubmatch(s, -1)
		//		fmt.Println(res)
		if res != nil {
			for _, v := range res {
				fmt.Println("matched: ", v[1])
			}
		}
	}
}
开发者ID:slaash,项目名称:scripts,代码行数:12,代码来源:shell_exec.go


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