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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                語法和JavaScript中的正則語法基本一致。 PHP中的正則函數: ![](https://img.kancloud.cn/44/0b/440b26c7500b71e4c9a6bfe8415735df_1049x425.png) # 1、preg_match() preg_match()返回匹配的次數,它的返回值是0或者是1. 0表示不匹配。 1表示匹配一次,因為preg_match在匹配一次之后就停止向后檢索了。和js中不加g的情況一樣。 查看匹配的結果: ![](https://img.kancloud.cn/a4/fb/a4fb36712f5a7e38dde28bd5df360831_655x364.png) 帶有子表達式的例子: ![](https://img.kancloud.cn/98/a6/98a62521792ab93d62b762517117d52a_754x169.png) # 2、preg_match_all(); 執行正則表達式的全局匹配,類似于js中的帶g的匹配。 ![](https://img.kancloud.cn/8d/4e/8d4e31ff9feafbc6c3f3648a59fd4071_750x304.png) 帶有子表達式的例子: ![](https://img.kancloud.cn/b7/7c/b77c8db5285fd0300507c793ac9ea922_907x430.png) # 3、preg_replace(); 執行正則替換。 替換字符串: ![](https://img.kancloud.cn/79/f8/79f819d5f3f6f26cbf0353ce7d7e614e_612x196.png) 帶有子表達式: ![](https://img.kancloud.cn/f4/02/f402c71f0f776145dd6ed47a4b5c08ca_581x218.png) 替換數組: # 4、案例:解決貪婪問題? 無論是JS中,還是PHP中,正則表達式的匹配模式默認都是貪婪模式。 ![](https://img.kancloud.cn/84/93/8493cddd8db3a94679897b449c718363_684x129.png) 上述代碼,查詢至少一個字母。但是在實際匹配的過程中,匹配到一個a之后,并沒有停止,而是繼續向后匹配,得到一個連續的字符串。這就是貪婪模式。 下面在正則表達式后面加入?,表示非貪婪模式: ![](https://img.kancloud.cn/92/13/921355d26d628945093ea315e6ac24d1_897x153.png) 默認是貪婪模式,必須使用非貪婪模式的例子: ![](https://img.kancloud.cn/c7/15/c71589c2d9559a93c17c0aff77577c8c_981x135.png) PHP中,強制非貪婪模式: 加入大寫的修飾符U即可。 ![](https://img.kancloud.cn/4c/5d/4c5db00f3f896998328878af3e347b7d_991x178.png) # 5、PHP中使用正則注意點 PHP中的正則表達式除了//以外,外面還要加引號,這個引號要用**單引號**。 ![](https://img.kancloud.cn/e2/08/e20831708100d428d1cb334ad86b029d_614x240.png)
                  <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>

                              哎呀哎呀视频在线观看