本文整理汇总了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
}
示例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)
}
}
}
示例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}
}
}
}
示例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
}
示例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
}
}
}
示例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]
}
示例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)
}
}
示例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
}
示例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
}
示例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
}
示例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)
}
}
}
示例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
}
示例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
}
示例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
}
示例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])
}
}
}
}