<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之旅 廣告
                [TOC] * * * * * ## 1 正則函數 ### 1-1 test() 檢測一個字符串是否匹配某個模式 ~~~ RegExpObject.test(string) ~~~ > string:必需,要檢測的字符串 > 返回值:如果字符串 string 中含有與 RegExpObject 匹配的文本,則返回 true,否則返回 false 實例 ~~~ <script type="text/javascript"> var str = "Visit W3School"; var patt1 = new RegExp("W3School"); var result = patt1.test(str); document.write("Result: " + result); </script> ~~~ 輸出 ~~~ Result: true ~~~ ### 1-2 replace() 替換字符串中的一些字符。 ~~~ stringObject.replace(regexp/substr,replacement) ~~~ > regexp/substr: > 子字符串或要替換模式的RegExp對象。默認替換第一個匹配子串,使用全局標識g,則替換所有匹配子串 > replacement: > 規定了替換文本或生成文本的函數 > 返回值,返回替換后字符串。 > 字符串每個匹配都將由字符串替換,$為索引,函數則第一個參數是匹配模式的字符串,接下來的參數是與模式中的子表達式匹配的字符串,可以有0個或多個這樣的參數。接下來的參數是一個整數,聲明了匹配的位置,最后一個參數是stringObject本身 實例1 ~~~ <script type="text/javascript"> var str="Visit Microsoft!" document.write(str.replace(/Microsoft/, "W3School")) </script> ~~~ 輸出 ~~~ Visit W3School! ~~~ 實例2 ~~~ <script type="text/javascript"> var str="Welcome to Microsoft! " str=str + "We are proud to announce that Microsoft has " str=str + "one of the largest Web Developers sites in the world." document.write(str.replace(/Microsoft/g, "W3School")) </script> ~~~ 輸出 ~~~ Welcome to W3School! We are proud to announce that W3School has one of the largest Web Developers sites in the world. ~~~ 實例3 ~~~ name = "Doe, John"; name.replace(/(\w+)\s*, \s*(\w+)/, "$2 $1"); ~~~ 實例4 ~~~ name = '"a", "b"'; name.replace(/"([^"]*)"/g, "'$1'"); ~~~ 實例5 ~~~ name = '"a", "b"'; name.replace(/"([^"]*)"/g, "'$1'"); ~~~ 實例6 ~~~ name = 'aaa bbb ccc'; uw=name.replace(/\b\w+\b/g, function(word){ return word.substring(0,1).toUpperCase()+word.substring(1);} ); ~~~ ### 1-3match() 在字符串內檢索指定的值,或找到一個或多個正則表達式的匹配。 ~~~ stringObject.match(searchvalue) stringObject.match(regexp) ~~~ > searchvalue:規定檢索的字符串值 > regexp: 規定匹配的模式的RegExp對象 > 返回值:存放匹配結果的數組,默認為第一個,全局/g則返回匹配結果 查找失敗返回null,查找成功返回包含一個的數組。第0個元素存放的是匹配文本,其余元素存放的是與正則表達式的子表達式匹配的文本。 > 無/g,返回數組還包含兩個對象屬性,index屬性起始字符的位置,input屬性對stringObject的引用 > 包含/g,執行全局搜索,搜索所有匹配子字符串,查找失敗返回null,匹配一個或多個,返回一個數組。全局返回不包含index屬性或input屬性 實例1 ~~~ <script type="text/javascript"> var str="Hello world!" document.write(str.match("world") + "<br />") document.write(str.match("World") + "<br />") document.write(str.match("worlld") + "<br />") document.write(str.match("world!")) </script> ~~~ 輸出 ~~~ world null null world! ~~~ 實例2 ~~~ <script type="text/javascript"> var str="1 plus 2 equal 3" document.write(str.match(/\d+/g)) </script> ~~~ 輸出 ~~~ 1,2,3 ~~~
                  <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>

                              哎呀哎呀视频在线观看