<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 正則表達式 在*OpenResty*中,同時存在兩套正則表達式規范: *Lua* 語言的規范和*Nginx*的規范,即使您對 *Lua* 語言中的規范非常熟悉,我們仍不建議使用 *Lua* 中的正則表達式。一是因為 *Lua* 中正則表達式的性能并不如 *Nginx* 中的正則表達式優秀;二是 *Lua* 中的正則表達式并不符合 *POSIX* 規范,而 *Nginx* 中實現的是標準的 *POSIX* 規范,后者明顯更具備通用性。 *Lua* 中的正則表達式與Nginx中的正則表達式相比,有5%-15%的性能損失,而且Lua將表達式編譯成Pattern之后,并不會將Pattern緩存,而是每此使用都重新編譯一遍,潛在地降低了性能。 *Nginx* 中的正則表達式可以通過參數緩存編譯過后的Pattern,不會有類似的性能損失。 o選項參數用于提高性能,指明該參數之后,被編譯的Pattern將會在worker進程中緩存,并且被當前worker進程的每次請求所共享。Pattern緩存的上限值通過lua_regex_cache_max_entries來修改。 ~~~ # nginx.conf location /test { content_by_lua_block { local regex = [[\\d+]] -- 參數"o"是開啟緩存必須的 local m = ngx.re.match("hello, 1234", regex, "o") if m then ngx.say(m[0]) else ngx.say("not matched!") end } } # 在網址中輸入"yourURL/test",即會在網頁中顯示1234。 ~~~ *Lua* 中正則表達式語法上最大的區別,*Lua* 使用 *'%'* 來進行轉義,而其他語言的正則表達式使用 *'\'* 符號來進行轉義。其次, *Lua* 中并不使用 *'?'* 來表示非貪婪匹配,而是定義了不同的字符來表示是否是貪婪匹配。定義如下: | 符號 | 匹配次數 | 匹配模式 | |-----|-----|-----| | + | 匹配前一字符 1 次或多次 | 非貪婪 | | * | 匹配前一字符 0 次或多次 | 貪婪 | | - | 匹配前一字符 0 次或多次 | 非貪婪 | | ? | 匹配前一字符 0 次或1次 | 僅用于此,不用于標識是否貪婪 | | 符號 | 匹配模式 | |-----|-----| | . | 任意字符 | | %a | 字母 | | %c | 控制字符 | | %d | 數字 | | %l | 小寫字母 | | %p | 標點字符 | | %s | 空白符 | | %u | 大寫字母 | | %w | 字母和數字 | | %x | 十六進制數字 | | %z | 代表 0 的字符 | #### Lua正則簡單匯總 - *string.find* 的基本應用是在目標串內搜索匹配指定的模式的串。函數如果找到匹配的串,就返回它的開始索引和結束索引,否則返回 *nil*。*find* 函數第三個參數是可選的:標示目標串中搜索的起始位置,例如當我們想實現一個迭代器時,可以傳進上一次調用時的結束索引,如果返回了一個*nil*值的話,說明查找結束了. ~~~ local s = "hello world" local i, j = string.find(s, "hello") print(i, j) --> 1 5 ~~~ - *string.gmatch* 我們也可以使用返回迭代器的方式。 ~~~ local s = "hello world from Lua" for w in string.gmatch(s, "%a+") do print(w) end -- output : -- hello -- world -- from -- Lua ~~~ - *string.gsub* 用來查找匹配模式的串,并將使用替換串其替換掉,但并不修改原字符串,而是返回一個修改后的字符串的副本,函數有目標串,模式串,替換串三個參數,使用范例如下: ~~~ local a = "Lua is cute" local b = string.gsub(a, "cute", "great") print(a) --> Lua is cute print(b) --> Lua is great ~~~ - 還有一點值得注意的是,'%b' 用來匹配對稱的字符,而不是一般正則表達式中的單詞的開始、結束。'%b' 用來匹配對稱的字符,而且采用貪婪匹配。常寫為 '%bxy' ,x 和 y 是任意兩個不同的字符;x 作為匹配的開始,y 作為匹配的結束。比如,'%b()' 匹配以 '(' 開始,以 ')' 結束的字符串: ~~~ --> a line print(string.gsub("a (enclosed (in) parentheses) line", "%b()", "")) ~~~
                  <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>

                              哎呀哎呀视频在线观看