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


Golang regexp.CompilePOSIX函数代码示例

本文整理汇总了Golang中regexp.CompilePOSIX函数的典型用法代码示例。如果您正苦于以下问题:Golang CompilePOSIX函数的具体用法?Golang CompilePOSIX怎么用?Golang CompilePOSIX使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: MapRegex

func (s *scrape) MapRegex(node xml.Node) (map[string]string, error) {
	if node.IsValid() == false {
		return nil, errors.New("Invalid node")
	}
	m := make(map[string]string, 1)
	inner := node.String()
	for k, v := range ScrapeRegex {
		// remove new line chars
		reg, _ := regexp.CompilePOSIX("\r\n|\r|\n")
		inner = reg.ReplaceAllString(inner, "")
		// get the real data
		reg, _ = regexp.CompilePOSIX(v[0])
		scraped := reg.FindString(inner)
		scraped = reg.ReplaceAllString(scraped, "$1")

		if scraped != "" {
			m[k] = scraped
		}
	}
	// Skip empty and unwanted
	if len(m) > 0 {
		if m[ScrapeMeta[IGNOREEMPTY]] != "" {
			return m, nil
		}
		return nil, nil
	}
	return nil, nil
}
开发者ID:oehip,项目名称:goscrape,代码行数:28,代码来源:scrape.go

示例2: validateHTTPIngressRuleValue

func validateHTTPIngressRuleValue(httpIngressRuleValue *extensions.HTTPIngressRuleValue, fldPath *field.Path) field.ErrorList {
	allErrs := field.ErrorList{}
	if len(httpIngressRuleValue.Paths) == 0 {
		allErrs = append(allErrs, field.Required(fldPath.Child("paths"), ""))
	}
	for i, rule := range httpIngressRuleValue.Paths {
		if len(rule.Path) > 0 {
			if !strings.HasPrefix(rule.Path, "/") {
				allErrs = append(allErrs, field.Invalid(fldPath.Child("paths").Index(i).Child("path"), rule.Path, "must be an absolute path"))
			}
			// TODO: More draconian path regex validation.
			// Path must be a valid regex. This is the basic requirement.
			// In addition to this any characters not allowed in a path per
			// RFC 3986 section-3.3 cannot appear as a literal in the regex.
			// Consider the example: http://host/valid?#bar, everything after
			// the last '/' is a valid regex that matches valid#bar, which
			// isn't a valid path, because the path terminates at the first ?
			// or #. A more sophisticated form of validation would detect that
			// the user is confusing url regexes with path regexes.
			_, err := regexp.CompilePOSIX(rule.Path)
			if err != nil {
				allErrs = append(allErrs, field.Invalid(fldPath.Child("paths").Index(i).Child("path"), rule.Path, "must be a valid regex"))
			}
		}
		allErrs = append(allErrs, validateIngressBackend(&rule.Backend, fldPath.Child("backend"))...)
	}
	return allErrs
}
开发者ID:MisaKondo,项目名称:kubernetes,代码行数:28,代码来源:validation.go

示例3: filterSingleDir

func filterSingleDir(path string, data []os.FileInfo) ([]os.FileInfo, error) {
	reg, err := regexp.CompilePOSIX(Config.fileregex)
	if err != nil {
		return nil, err
	}

	//搜索出生成文件
	genfile := GetGenerateFileName(path)

	//过滤出需要生成的文件
	newdata := []os.FileInfo{}
	var genfiledata os.FileInfo
	for _, singleFileInfo := range data {
		if singleFileInfo.Name() == genfile {
			genfiledata = singleFileInfo
			continue
		}
		if reg.Match([]byte(path+"/"+singleFileInfo.Name())) == false {
			continue
		}
		newdata = append(newdata, singleFileInfo)
	}

	//判断是否需要生成文件
	for _, singleFileInfo := range newdata {
		if genfiledata == nil || singleFileInfo.ModTime().After(genfiledata.ModTime()) {
			return newdata, nil
		}
	}

	//FIXME 暂时不做增量更新策略
	return newdata, nil
}
开发者ID:fishedee,项目名称:fishgo,代码行数:33,代码来源:filter.go

示例4: Extract_tld

//从rawurl中提取顶级域名服务商,tldTop用来查询,topDomain用来找注册商服务器,domainName用来查询的域名
func Extract_tld(rawurl string) (tldTop, topDomain, domainName string) {
	filename := "./res/data.txt"
	data := openfile(filename)
	host := extract_host(rawurl)
	host_slice := strings.Split(host, ".")
	length := len(host_slice)
	tldTop = host_slice[length-1]
	// fmt.Println(tldTop)
	//得到顶级域名和主机名
	for i := 0; i < length; i++ {
		expr := ""
		for j := i; j < length; j++ {
			expr = expr + "." + host_slice[j]
		}

		reg, _ := regexp.CompilePOSIX("^" + expr[1:])
		// reg, _ := regexp.CompilePOSIX("^" + expr[1:] + "$")
		if reg.MatchString(data) {
			if i != 0 {
				domainName = host_slice[i-1] + expr
			} else {
				domainName = expr
			}
			topDomain = expr[1:]
			return
		}
	}
	return
}
开发者ID:hetykai,项目名称:GetDomainWhois,代码行数:30,代码来源:gettld.go

示例5: NewTerm

func NewTerm(kind TKind_t, lfactor *Factor, list *List, rfactor *Factor, expr *Expr) (*Term, error) {
	t := new(Term)
	t.Kind = kind
	switch kind {
	case IN, NI:
		t.Left = lfactor
		t.Right = list
	case GT, LT, EQ, NE, GE, LE:
		t.Left = lfactor
		t.Right = rfactor
	case MA, NM:
		t.Left = lfactor
		if v, err := cast2string(rfactor.Value); err != nil {
			return t, err
		} else {
			if t.Right, err = regexp.CompilePOSIX(v); err != nil {
				return t, err
			}
		}
	case EXPR:
		t.Left = nil
		t.Right = expr
	}
	return t, nil
}
开发者ID:soforth,项目名称:gohap,代码行数:25,代码来源:ast.go

示例6: GetRegexp

func (s *StreamServer) GetRegexp() (map[string][]*regexp.Regexp, error) {
	consulSetting := make(map[string][]*regexp.Regexp)
	kv := s.client.KV()
	pairs, _, err := kv.List(s.ConsulKey, nil)
	if err != nil {
		return consulSetting, err
	}
	size := len(s.ConsulKey) + 1
	for _, value := range pairs {
		if len(value.Key) > size {
			var regs []string
			if err := json.Unmarshal(value.Value, &regs); err == nil {
				var rs []*regexp.Regexp
				for _, v := range regs {
					x, e := regexp.CompilePOSIX(v)
					if e != nil {
						log.Println("get regexp", e)
						continue
					}
					rs = append(rs, x)
				}
				consulSetting[value.Key[size:]] = rs
			}
		}
	}
	return consulSetting, err
}
开发者ID:datastream,项目名称:nsqtools,代码行数:27,代码来源:streamserver.go

示例7: main

func main() {
	var re *regexp.Regexp
	var err error
	visited := newVisitTracker()
	if *filter != "" {
		re, err = regexp.CompilePOSIX(*filter)
		if err != nil {
			log.Fatal("Failed to compile regex", err)
		}
	}

	url, err := url.ParseRequestURI(*webRoot)
	if err != nil {
		log.Fatal("Invalid root URL:", err)
	}
	host = url.Scheme + "://" + url.Host

	//probe root page
	rootPage, err := getPage(*webRoot)
	if err != nil {
		log.Fatal("Failed to get root page", err)
	}

	urls := extractURLs(rootPage)
	walkUrls(visited, urls, *webRoot, re, *ft)
}
开发者ID:traetox,项目名称:webrip,代码行数:26,代码来源:main.go

示例8: NewPOSIX

// NewPOSIX complies the provided POSIX regex.
func NewPOSIX(regex string) (*Regexp, error) {
	re, err := regexp.CompilePOSIX(regex)
	if err != nil {
		return nil, err
	}

	return &Regexp{RE: re}, nil
}
开发者ID:knq,项目名称:reutil,代码行数:9,代码来源:regexp.go

示例9: ieManage

//ie,ru顶级域名处理函数,注册人提取,无电话邮箱
func ieManage(details string) (regName, regPhone, regEmail string) {
	re, _ := regexp.CompilePOSIX("person:.*|registrar:.*|Registrar Name:.*")
	regName = re.FindString(details)
	if len(regName) != 0 {
		regName = strings.TrimSpace(strings.Split(regName, ":")[1])
	}
	return
}
开发者ID:hetykai,项目名称:GetDomainWhois,代码行数:9,代码来源:extractinfo.go

示例10: Set

func (e *Excludes) Set(value string) error {
	r, err := regexp.CompilePOSIX(value)
	if err == nil {
		*e = append(*e, *r)
	} else {
		log.Error("Error:", err.Error())
	}

	return nil
}
开发者ID:mefellows,项目名称:parity,代码行数:10,代码来源:config.go

示例11: AddRegexp

func (c *Condition) AddRegexp(r map[string]string) error {

	for field, value := range r {
		reg, err := regexp.CompilePOSIX(value)
		if err != nil {
			return err
		}
		c.Regexp[field] = reg
	}
	return nil
}
开发者ID:yan2jared,项目名称:beats,代码行数:11,代码来源:condition.go

示例12: LinuxPath

// TODO: Move this into a Windows specific build function and
//       make unix a no-op
func LinuxPath(path string) string {
	// Strip drive prefix c:/ etc.
	// TODO: Need to find a way to deal with paths properly (i.e. what if multiple drives!)
	r, _ := regexp.CompilePOSIX("([a-zA-Z]:)(\\.*)")
	if r.MatchString(path) {
		path = r.ReplaceAllString(path, "$2")
	}

	path = strings.Replace(path, "\\", "/", -1)
	path = strings.Replace(path, "//", "/", -1)
	return path
}
开发者ID:mefellows,项目名称:parity,代码行数:14,代码来源:utils.go

示例13: compile

func compile(pattern string, options GrepOptions) (*regexp.Regexp, error) {
	if options.IsPerl {
		if options.IsIgnoreCase && !strings.HasPrefix(pattern, "(?") {
			pattern = "(?i)" + pattern
		}
		return regexp.Compile(pattern)
	} else {
		if options.IsIgnoreCase {
			pattern = strings.ToLower(pattern)
		}
		return regexp.CompilePOSIX(pattern)
	}
}
开发者ID:jayvansantos,项目名称:someutils,代码行数:13,代码来源:grep.go

示例14: main

func main() {
	flag.Parse()

	if *showVersionShort || *showVersionLong {
		fmt.Println("0.2")
		return
	}

	conf, err := sup.NewSupfile(*supfile)
	if err != nil {
		log.Fatal(err)
	}

	// Parse network and commands to be run from args.
	network, commands, err := parseArgs(conf)
	if err != nil {
		log.Fatal(err)
	}

	// --only option to filter hosts
	if *onlyHosts != "" {
		expr, err := regexp.CompilePOSIX(*onlyHosts)
		if err != nil {
			log.Fatal(err)
		}

		var hosts []string
		for _, host := range network.Hosts {
			if expr.MatchString(host) {
				hosts = append(hosts, host)
			}
		}
		if len(hosts) == 0 {
			log.Fatal(fmt.Errorf("no hosts match '%v' regexp", *onlyHosts))
		}
		network.Hosts = hosts
	}

	// Create new Stackup app.
	app, err := sup.New(conf)
	if err != nil {
		log.Fatal(err)
	}

	// Run all the commands in the given network.
	err = app.Run(network, commands...)
	if err != nil {
		log.Fatal(err)
	}
}
开发者ID:YyyZeroToHero,项目名称:sup,代码行数:50,代码来源:main.go

示例15: InitRegexps

// InitRegexps initializes a list of compiled regular expressions.
func InitRegexps(exprs []string) ([]*regexp.Regexp, error) {

	result := []*regexp.Regexp{}

	for _, exp := range exprs {

		rexp, err := regexp.CompilePOSIX(exp)
		if err != nil {
			logp.Err("Fail to compile the regexp %s: %s", exp, err)
			return nil, err
		}
		result = append(result, rexp)
	}
	return result, nil
}
开发者ID:radoondas,项目名称:apachebeat,代码行数:16,代码来源:util.go


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