當前位置: 首頁>>代碼示例>>Golang>>正文


Golang regexp.MatchString函數代碼示例

本文整理匯總了Golang中regexp.MatchString函數的典型用法代碼示例。如果您正苦於以下問題:Golang MatchString函數的具體用法?Golang MatchString怎麽用?Golang MatchString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了MatchString函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: clear

func clear() error {
	if err := filepath.Walk("public", func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		if m, _ := regexp.MatchString("~$", path); m {
			return nil
		}
		// Remove auto-generated html files.
		m, err := regexp.MatchString(".html$", path)
		if err != nil {
			return err
		}
		if m {
			return os.Remove(path)
		}
		// Remove example resources that are copied.
		m, err = regexp.MatchString("^public/examples/_resources/images$", path)
		if err != nil {
			return err
		}
		if m {
			if err := os.RemoveAll(path); err != nil {
				return err
			}
			return filepath.SkipDir
		}
		return nil
	}); err != nil {
		return err
	}
	return nil
}
開發者ID:carriercomm,項目名稱:ebiten,代碼行數:33,代碼來源:gen.go

示例2: newProjectStep

func newProjectStep(data *WizardData) {
	fmt.Print("Enter name of new project: ")
	projectParam := &phraseapp.ProjectParams{}
	fmt.Scanln(&projectParam.Name)

	res, err := phraseapp.ProjectCreate(projectParam)
	if err != nil {
		success, match_err := regexp.MatchString("401", err.Error())
		if match_err != nil {
			fmt.Println(err.Error())
			panic(match_err.Error())
		}
		if success {
			data.AccessToken = ""
			DisplayWizard(data, "", fmt.Sprintf("Argument Error: Your AccessToken '%s' has no write scope. Please create a new Access Token with read and write scope.", data.AccessToken))
		} else {
			success, match_err := regexp.MatchString("Validation failed", err.Error())
			if match_err != nil {
				fmt.Println(err.Error())
				panic(match_err.Error())
			}
			if success {
				DisplayWizard(data, "newProject", err.Error())
				return
			} else {
				panic(err.Error())
			}
		}
	} else {
		data.ProjectId = res.Id
		DisplayWizard(data, next(data), "")
		return
	}
}
開發者ID:marxbeck,項目名稱:phraseapp-client,代碼行數:34,代碼來源:wizard.go

示例3: getBody

// 根據網址 獲取內容,確定是否需要進一步處理
func getBody(url string) (string, string, error) {
	//根據url首先判斷是否讀取
	if strings.Contains(url, ".hqew.com/ic") {
		res, err := http.Get(url)
		if err != nil {
			fmt.Println("connect error")
			log.Fatal(err)
		}
		robots, err := ioutil.ReadAll(res.Body)
		if err != nil {
			fmt.Println("connect error")
			log.Fatal(err)
		}
		res.Body.Close()
		body := string(robots)
		if len(body) == 0 {
			fmt.Println("null body")
		}

		//
		isMatch_stock, _ := regexp.MatchString(
			`xh ic_ico1`, body)
		isMatch_black, _ := regexp.MatchString(
			`target="_blank" class="g_fb"`, body)
		//isMatch := isMatch_stock || isMatch_black
		if isMatch_stock == true {
			return body, "stock", nil
		} else if isMatch_black == true {
			return "NotStock", "black", nil
		}
		return "", "false", nil
	} else {
		return "", "false", nil
	}
}
開發者ID:huabo,項目名稱:hqew,代碼行數:36,代碼來源:hqew_model.go

示例4: main

func main() {
	if len(os.Args) != 2 {
		fmt.Println("Please select one picture to makeascii...")
		return
	}
	fileName := os.Args[1]
	isJpeg, _ := regexp.MatchString(".+\\.jpg", fileName)
	isPng, _ := regexp.MatchString(".+\\.png", fileName)
	var picture image.Image
	var imageErr error
	fileIn, errIn := os.Open(fileName)
	if errIn != nil {
		fmt.Println(errIn.Error())
		return
	}
	if isJpeg {
		picture, imageErr = jpeg.Decode(fileIn)
	} else if isPng {
		picture, imageErr = png.Decode(fileIn)
	} else {
		fmt.Println("File type is not supported...")
		return
	}
	if imageErr != nil {
		fmt.Println(imageErr.Error())
		return
	}
	fmt.Print(MakeAscii(GetImage(picture)))
}
開發者ID:bjh83,項目名稱:makeascii,代碼行數:29,代碼來源:makeascii.go

示例5: TestAudit

func TestAudit(t *testing.T) {
	var buf bytes.Buffer
	attributeGetter := apiserver.NewRequestAttributeGetter(&fakeRequestContextMapper{},
		&apiserver.RequestInfoResolver{APIPrefixes: sets.NewString("api", "apis"), GrouplessAPIPrefixes: sets.NewString("api")})
	handler := WithAudit(&fakeHTTPHandler{}, attributeGetter, &buf)
	req, _ := http.NewRequest("GET", "/api/v1/namespaces/default/pods", nil)
	req.RemoteAddr = "127.0.0.1"
	handler.ServeHTTP(httptest.NewRecorder(), req)
	line := strings.Split(strings.TrimSpace(buf.String()), "\n")
	if len(line) != 2 {
		t.Fatalf("Unexpected amount of lines in audit log: %d", len(line))
	}
	match, err := regexp.MatchString(`[\d\:\-\.\+TZ]+ AUDIT: id="[\w-]+" ip="127.0.0.1" method="GET" user="admin" as="<self>" asgroups="<lookup>" namespace="default" uri="/api/v1/namespaces/default/pods"`, line[0])
	if err != nil {
		t.Errorf("Unexpected error matching first line: %v", err)
	}
	if !match {
		t.Errorf("Unexpected first line of audit: %s", line[0])
	}
	match, err = regexp.MatchString(`[\d\:\-\.\+TZ]+ AUDIT: id="[\w-]+" response="200"`, line[1])
	if err != nil {
		t.Errorf("Unexpected error matching second line: %v", err)
	}
	if !match {
		t.Errorf("Unexpected second line of audit: %s", line[1])
	}
}
開發者ID:juanluisvaladas,項目名稱:origin,代碼行數:27,代碼來源:audit_test.go

示例6: TestMutexProfile

func TestMutexProfile(t *testing.T) {
	old := runtime.SetMutexProfileFraction(1)
	defer runtime.SetMutexProfileFraction(old)
	if old != 0 {
		t.Fatalf("need MutexProfileRate 0, got %d", old)
	}

	blockMutex()

	var w bytes.Buffer
	Lookup("mutex").WriteTo(&w, 1)
	prof := w.String()

	if !strings.HasPrefix(prof, "--- mutex:\ncycles/second=") {
		t.Errorf("Bad profile header:\n%v", prof)
	}
	prof = strings.Trim(prof, "\n")
	lines := strings.Split(prof, "\n")
	if len(lines) != 6 {
		t.Errorf("expected 6 lines, got %d %q\n%s", len(lines), prof, prof)
	}
	if len(lines) < 6 {
		return
	}
	// checking that the line is like "35258904 1 @ 0x48288d 0x47cd28 0x458931"
	r2 := `^\d+ 1 @(?: 0x[[:xdigit:]]+)+`
	//r2 := "^[0-9]+ 1 @ 0x[0-9a-f x]+$"
	if ok, err := regexp.MatchString(r2, lines[3]); err != nil || !ok {
		t.Errorf("%q didn't match %q", lines[3], r2)
	}
	r3 := "^#.*runtime/pprof_test.blockMutex.*$"
	if ok, err := regexp.MatchString(r3, lines[5]); err != nil || !ok {
		t.Errorf("%q didn't match %q", lines[5], r3)
	}
}
開發者ID:Harvey-OS,項目名稱:go,代碼行數:35,代碼來源:pprof_test.go

示例7: checkFunParam

func checkFunParam(fun type_sqlfun) {
	switch fun.name {
	case "regsub":
		if len(fun.params) != 3 {
			parseError(fun.name + " function params error")
		}
		re := regexp.MustCompile("^\\$\\d{1,3}")
		if !re.MatchString(fun.params[0]) {
			parseError(fun.name + " function params error")
		}
	case "strsub":
		if len(fun.params) > 3 || len(fun.params) < 2 {
			parseError(fun.name + " function params num error")
		}
		m, _ := regexp.MatchString("^\\$\\d{1,3}", fun.params[0])
		fp("^\\$\\d{1,3}")
		if !m {
			parseError(fun.name + " function params error")
		}

	case "count,sum,avg,max,min":
		if len(fun.params) != 1 {
			parseError(fun.name + " function params error")
		}

		m, _ := regexp.MatchString("^\\$\\d{1,3}", fun.params[0])
		if !m {
			parseError(fun.name + " function params error")
		}
	}
}
開發者ID:kjfcpua,項目名稱:myselect,代碼行數:31,代碼來源:myselect.go

示例8: GetMetricName

func (c *CollectdJSON) GetMetricName(index int) string {
	metricName := c.Host + "_" + c.Plugin
	if len(c.PluginInstance) > 0 {
		if matched, _ := regexp.MatchString(`^\d+$`, c.PluginInstance); matched {
			metricName += c.PluginInstance
		} else {
			metricName += "_" + c.PluginInstance
		}
	}
	tSize := len(c.Type)
	pSize := len(c.Plugin)
	if tSize > 0 {
		if pSize <= tSize && c.Type[:pSize] == c.Plugin {
			metricName += c.Type[pSize:]
		} else {
			metricName += "." + c.Type
		}
	}
	if len(c.TypeInstance) > 0 {
		if matched, _ := regexp.MatchString(`^\d+$`, c.TypeInstance); matched {
			metricName += c.TypeInstance
		} else {
			metricName += "_" + c.TypeInstance
		}
	}
	if c.DataSetNames[index] != "value" {
		metricName += "." + c.DataSetNames[index]
	}
	return metricName
}
開發者ID:justzx2011,項目名稱:tools,代碼行數:30,代碼來源:collectd.go

示例9: detectProdConfig

func detectProdConfig(useosxt bool) string {
	var levelUp string
	var curDir string
	sep := string(filepath.Separator)

	if useosxt {
		curDir, _ = os.Getwd()
	} else {
		curDir, _ = osext.ExecutableFolder()
	}

	//detect from test or console
	match, _ := regexp.MatchString("_test", curDir)
	matchArgs, _ := regexp.MatchString("arguments", curDir)
	matchTestsDir, _ := regexp.MatchString("tests", curDir)
	if match || matchArgs || matchTestsDir {
		if matchTestsDir {
			levelUp = ".."
		}
		curDir, _ = filepath.Abs(curDir + sep + levelUp + sep)
	}

	CurrDirectory = curDir
	configDir, _ := filepath.Abs(curDir + sep + CONFIG_DIR + sep)
	appConfig := configDir + sep + CONFIG_FILE
	appProdConfig := configDir + sep + PRODUCTION_FOLDER + sep + CONFIG_FILE
	if fileExists(appProdConfig) {
		appConfig = appProdConfig
	} else if !useosxt {
		appConfig = detectProdConfig(true)
	}

	return appConfig
}
開發者ID:andboson,項目名稱:configlog,代碼行數:34,代碼來源:configlog.go

示例10: TestUserSetRoleWithNoVal_SystemTest

func TestUserSetRoleWithNoVal_SystemTest(t *testing.T) {
	for _, dut := range duts {
		cmds := []string{
			"no username test",
			"username test role network-admin nopassword",
		}
		if ok := dut.Config(cmds...); !ok {
			t.Fatalf("dut.Config() failure")
		}

		user := User(dut)

		config := user.GetSection()
		if found, _ := regexp.MatchString(`username test privilege 1 role network-admin nopassword`, config); !found {
			t.Fatalf("\"username test privilege 1\" expected but not seen under "+
				"user section.\n[%s]", config)
		}

		if ok := user.SetRole("test", ""); !ok {
			t.Fatalf("SetRole config for user failed")
		}

		config = user.GetSection()
		if found, _ := regexp.MatchString(`username test privilege 1 role network-admin nopassword`, config); found {
			t.Fatalf("\"username test privilege 1 role network-admin nopasswd\" expected but not seen under "+
				"user section.\n[%s]", config)
		}
	}
}
開發者ID:sysbot,項目名稱:goeapi,代碼行數:29,代碼來源:users_test.go

示例11: TestUserSetSSHKeyWithNoVal_SystemTest

func TestUserSetSSHKeyWithNoVal_SystemTest(t *testing.T) {
	for _, dut := range duts {
		cmds := []string{
			"no username test",
			"username test nopassword",
		}
		if ok := dut.Config(cmds...); !ok {
			t.Fatalf("dut.Config() failure")
		}

		user := User(dut)

		config := user.GetSection()
		if found, _ := regexp.MatchString(`username test privilege 1 nopassword`, config); !found {
			t.Fatalf("\"username test privilege 1\" expected but not seen under "+
				"user section.\n[%s]", config)
		}

		if ok := user.SetSshkey("test", ""); !ok {
			t.Fatalf("SetSshkey config for user failed")
		}

		config = user.GetSection()
		configStr := "username test sshkey " + regexp.QuoteMeta(testSSHKey)
		if found, _ := regexp.MatchString(configStr, config); found {
			t.Fatalf("\"%s\" NOT expected but not seen under "+
				"user section.\n[%s]", configStr, config)
		}
	}
}
開發者ID:sysbot,項目名稱:goeapi,代碼行數:30,代碼來源:users_test.go

示例12: TestUserSetPrivWithInvalidVal_SystemTest

func TestUserSetPrivWithInvalidVal_SystemTest(t *testing.T) {
	for _, dut := range duts {
		cmds := []string{
			"no username test",
			"username test privilege 8 nopassword",
		}
		if ok := dut.Config(cmds...); !ok {
			t.Fatalf("dut.Config() failure")
		}

		user := User(dut)

		config := user.GetSection()
		if found, _ := regexp.MatchString(`username test privilege 8 nopassword`, config); !found {
			t.Fatalf("\"username test privilege 8\" expected but not seen under "+
				"user section.\n[%s]", config)
		}

		if ok, err := user.SetPrivilege("test", 65535); ok || err == nil {
			t.Fatalf("SetPrivilege config for user failed")
		}

		config = user.GetSection()
		if found, _ := regexp.MatchString(`username test privilege 8 nopassword`, config); !found {
			t.Fatalf("\"username test privilege 8 nopasswd\" expected but not seen under "+
				"user section.\n[%s]", config)
		}
	}
}
開發者ID:sysbot,項目名稱:goeapi,代碼行數:29,代碼來源:users_test.go

示例13: TestUserDelete_SystemTest

func TestUserDelete_SystemTest(t *testing.T) {
	for _, dut := range duts {
		cmds := []string{
			"no username test",
			"username test nopassword",
		}
		if ok := dut.Config(cmds...); !ok {
			t.Fatalf("dut.Config() failure")
		}

		user := User(dut)

		config := user.GetSection()
		if found, _ := regexp.MatchString(`username test privilege 1 nopassword`, config); !found {
			t.Fatalf("\"username test privilege 1\" expected but not seen under "+
				"user section.\n[%s]", config)
		}

		if ok := user.Delete("test"); !ok {
			t.Fatalf("Delete of user failed")
		}

		config = user.GetSection()
		if found, _ := regexp.MatchString(`username test privilege 1 nopassword`, config); found {
			t.Fatalf("\"username test privilege 1\" expected but not seen under "+
				"user section.\n[%s]", config)
		}
	}
}
開發者ID:sysbot,項目名稱:goeapi,代碼行數:29,代碼來源:users_test.go

示例14: TestUserCreateWithSecret_SystemTest

func TestUserCreateWithSecret_SystemTest(t *testing.T) {
	for _, dut := range duts {
		cmds := []string{
			"no username test",
		}
		if ok := dut.Config(cmds...); !ok {
			t.Fatalf("dut.Config() failure")
		}

		user := User(dut)

		config := user.GetSection()
		if found, _ := regexp.MatchString(`username test privilege 1`, config); found {
			t.Fatalf("\"username test privilege 1\" NOT expected but not seen under "+
				"user section.\n[%s]", config)
		}

		if ok, err := user.CreateWithSecret("test", "password", "cleartext"); !ok || err != nil {
			t.Fatalf("CreateWithSecret of user failed")
		}

		config = user.GetSection()
		if found, _ := regexp.MatchString(`username test`, config); !found {
			t.Fatalf("\"username test privilege 1\" expected but not seen under "+
				"user section.\n[%s]", config)
		}
	}
}
開發者ID:sysbot,項目名稱:goeapi,代碼行數:28,代碼來源:users_test.go

示例15: parseStartLink

func parseStartLink() {
	fmt.Println("Input url: ")
	fmt.Scanf("%s", &url)
	firstDoc, err := goquery.NewDocument(url)
	checkerr(err)
	firstDoc.Find("tbody").Each(func(i int, tbody *goquery.Selection) {
		tbody.Find(".description").Each(func(j int, s *goquery.Selection) {
			link, _ := s.Find("a").Attr("href")
			x, _ := regexp.MatchString(`https://www.exploit-db.com/exploits/.....`, link)
			if x == true {
				file, err := os.OpenFile("temp.txt", os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666)
				checkerr(err)
				_, err = file.WriteString(link + "\n")
				checkerr(err)
				file.Close()
			}
			y, _ := regexp.MatchString(`/docs/......pdf`, link)
			if y == true {
				wasteUrl, err := os.OpenFile("waste.txt", os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666)
				checkerr(err)
				_, err = wasteUrl.WriteString(link)
				checkerr(err)
				wasteUrl.Close()
			}
		})
	})
}
開發者ID:podliy16,項目名稱:gogogog,代碼行數:27,代碼來源:parser.go


注:本文中的regexp.MatchString函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。