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


Golang Regexp.NumSubexp方法代码示例

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


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

示例1: Match

func (c *Commit) Match(regex *regexp.Regexp) *string {
	if regex.NumSubexp() == 1 {
		m := regex.FindStringSubmatch(c.text)
		if m == nil {
			return nil
		}
		return &m[1]
	} else {
		if !regex.MatchString(c.text) {
			return nil
		}
		return &c.text
	}
	return nil
}
开发者ID:cmccabe,项目名称:cmccabe-hbin,代码行数:15,代码来源:jirafun.go

示例2: checkRegexp

func checkRegexp(t *testing.T, r *regexp.Regexp, m regexpMatch) {
	matches := r.FindStringSubmatch(m.input)
	if m.match && matches != nil {
		if len(matches) != (r.NumSubexp()+1) || matches[0] != m.input {
			t.Fatalf("Bad match result %#v for %q", matches, m.input)
		}
		if len(matches) < (len(m.subs) + 1) {
			t.Errorf("Expected %d sub matches, only have %d for %q", len(m.subs), len(matches)-1, m.input)
		}
		for i := range m.subs {
			if m.subs[i] != matches[i+1] {
				t.Errorf("Unexpected submatch %d: %q, expected %q for %q", i+1, matches[i+1], m.subs[i], m.input)
			}
		}
	} else if m.match {
		t.Errorf("Expected match for %q", m.input)
	} else if matches != nil {
		t.Errorf("Unexpected match for %q", m.input)
	}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:20,代码来源:regexp_test.go

示例3: New


//.........这里部分代码省略.........
				} else if responseFunc, ok := typ.MethodByName(fld.Name + "Responses"); ok {
					responseList := responseFunc.Func.Call([]reflect.Value{})[0].Interface().(map[string]ResponseT)
					for responseStatus, responseSchema := range responseList {
						SwaggerParameter, err = GetSwaggerType(reflect.TypeOf(responseSchema.TypeReturned))
						if err != nil {
							return nil, err
						}
						if SwaggerParameter == nil {
							responses[responseStatus] = SwaggerResponseT{
								Description: responseSchema.Description,
							}
						} else {
							responses[responseStatus] = SwaggerResponseT{
								Description: responseSchema.Description,
								Schema:      SwaggerParameter.Schema,
							}
						}
					}
				}

				resp.Swagger.Paths[path][strings.ToLower(httpmethod)] = SwaggerOperationT{
					Schemes:     proto,
					OperationId: methodName,
					Parameters:  swaggerParameters,
					Responses:   responses,
					Consumes:    []string{consumes},
					Produces:    []string{produces},
				}

				Goose.New.Logf(5, "Registering marshalers: %s, %s", consumes, produces)

				resp.MatchedOps[MatchedOpsIndex] = len(resp.Svc)
				reComp = regexp.MustCompile(re)
				MatchedOpsIndex += reComp.NumSubexp() + 1

				/*
				   switch strings.ToLower(fld.Tag.Get("access")) {
				      case "none":     accesstype = AccessNone
				      case "auth":     accesstype = AccessAuth
				      case "authinfo": accesstype = AccessAuthInfo
				      default:         accesstype = AccessAuth
				   }
				*/

				resp.Svc = append(resp.Svc, UrlNode{
					Proto:     proto,
					Path:      path,
					consumes:  consumes,
					produces:  produces,
					Headers:   headers,
					Query:     query,
					Body:      postFields,
					ParmNames: parmnames,
					Handle:    buildHandle(svcRecv, method, pt, resp.Access),
					//               Access:    resp.Access,
				})

				reAllOps += "|(" + re + ")"
				Goose.New.Logf(6, "Partial Matcher for %s is %s", path, reAllOps)

				if resp.EnableCORS {
					index := len(resp.Svc)
					if optIndex == nil {
						optIndex = map[string]int{path: index}
					} else if index, ok = optIndex[path]; ok {
						for _, HdrNew = range headers {
开发者ID:luisfurquim,项目名称:stonelizard,代码行数:67,代码来源:stonelizard.go

示例4: main

func main() {
	flag.Parse()

	fargs := flag.Args()
	if len(fargs) == 0 {
		flag.Usage()
		os.Exit(1)
	}

	patt := fargs[0]
	delim := string(patt[1])
	parts := strings.Split(patt, delim)

	sedFrom := parts[1]
	sedTo := parts[2]
	sedFlags := parts[3]

	var pattFlags syntax.Flags

	if ere || erE {
		pattFlags |= syntax.Perl
	}
	if strings.Contains(sedFlags, "i") {
		pattFlags |= syntax.FoldCase
	}

	sedFlagG = strings.Contains(sedFlags, "g")

	rxParsed, err := syntax.Parse(sedFrom, pattFlags)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	rxsz := rxParsed.String()

	var rx *regexp.Regexp
	if pattFlags&syntax.Perl > 0 {
		rx = regexp.MustCompile(rxsz)
	} else {
		rx = regexp.MustCompilePOSIX(rxsz)
	}

	var maxReplIndex int
	if m := replIndicesLenRx.FindAllStringSubmatch(sedTo, -1); len(m) > 0 {
		for _, sm := range m {
			i, err := strconv.Atoi(sm[1])
			if err != nil {
				fmt.Println(err.Error())
				os.Exit(1)
			}
			if i > maxReplIndex {
				maxReplIndex = i
			}
		}
	}

	if maxReplIndex > rx.NumSubexp() {
		fmt.Println("sed: replacement indices exceed capture groups")
		os.Exit(1)
	}

	switch len(fargs) {
	case 1:
		if sed(rx, sedTo, os.Stdin) {
			os.Exit(0)
		}
		os.Exit(1)
	case 2:
		fr, err := os.Open(fargs[1])
		if err != nil {
			fmt.Println(err.Error())
			os.Exit(1)
		}
		defer fr.Close()
		if sed(rx, sedTo, fr) {
			os.Exit(0)
		}
		os.Exit(1)
	}
}
开发者ID:akutz,项目名称:gnixutils,代码行数:81,代码来源:sed.go


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