<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Go 正則表達式 Go內置了對正則表達式的支持,這里是一般的正則表達式常規用法的例子。 ```go package main import "bytes" import "fmt" import "regexp" func main() { // 測試模式是否匹配字符串,括號里面的意思是 // 至少有一個a-z之間的字符存在 match, _ := regexp.MatchString("p([a-z]+)ch", "peach") fmt.Println(match) // 上面我們直接使用了字符串匹配的正則表達式, // 但是對于其他的正則匹配任務,你需要使用 // `Compile`來使用一個優化過的正則對象 r, _ := regexp.Compile("p([a-z]+)ch") // 正則結構體對象有很多方法可以使用,比如上面的例子 // 也可以像下面這么寫 fmt.Println(r.MatchString("peach")) // 這個方法檢測字符串參數是否存在正則所約束的匹配 fmt.Println(r.FindString("peach punch")) // 這個方法查找第一次匹配的索引,并返回匹配字符串 // 的起始索引和結束索引,而不是匹配的字符串 fmt.Println(r.FindStringIndex("peach punch")) // 這個方法返回全局匹配的字符串和局部匹配的字符,比如 // 這里會返回匹配`p([a-z]+)ch`的字符串 // 和匹配`([a-z]+)`的字符串 fmt.Println(r.FindStringSubmatch("peach punch")) // 和上面的方法一樣,不同的是返回全局匹配和局部匹配的 // 起始索引和結束索引 fmt.Println(r.FindStringSubmatchIndex("peach punch")) // 這個方法返回所有正則匹配的字符,不僅僅是第一個 fmt.Println(r.FindAllString("peach punch pinch", -1)) // 這個方法返回所有全局匹配和局部匹配的字符串起始索引 // 和結束索引 fmt.Println(r.FindAllStringSubmatchIndex("peach punch pinch", -1)) // 為這個方法提供一個正整數參數來限制匹配數量 fmt.Println(r.FindAllString("peach punch pinch", 2)) //上面我們都是用了諸如`MatchString`這樣的方法,其實 // 我們也可以使用`[]byte`作為參數,并且使用`Match` // 這樣的方法名 fmt.Println(r.Match([]byte("peach"))) // 當使用正則表達式來創建常量的時候,你可以使用`MustCompile` // 因為`Compile`返回兩個值 r = regexp.MustCompile("p([a-z]+)ch") fmt.Println(r) // regexp包也可以用來將字符串的一部分替換為其他的值 fmt.Println(r.ReplaceAllString("a peach", "<fruit>")) // `Func`變量可以讓你將所有匹配的字符串都經過該函數處理 // 轉變為所需要的值 in := []byte("a peach") out := r.ReplaceAllFunc(in, bytes.ToUpper) fmt.Println(string(out)) } ``` 運行結果 ``` true true peach [0 5] [peach ea] [0 5 1 3] [peach punch pinch] [[0 5 1 3] [6 11 7 9] [12 17 13 15]] [peach punch] true p([a-z]+)ch a <fruit> a PEACH ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看