成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

Javascript 正則使用第一篇

CoXie / 2796人閱讀

摘要:參數(shù)說明此處賦值,為了更好的觀察的值,位置運(yùn)行結(jié)果運(yùn)行結(jié)果運(yùn)行結(jié)果第一次匹配第二次匹配第三次匹配第四次匹配第五次匹配第六次匹配運(yùn)行結(jié)果運(yùn)行結(jié)果如果使用了全局匹配則只顯示匹配到的全部字符串。也沒有屬性運(yùn)行結(jié)果運(yùn)行結(jié)果

replace() 參數(shù)說明

@param match
The matched substring. (Corresponds to $&.)

@param p1

@param p2

@param p3
The nth parenthesized submatch string,
provided the first argument to replace was a RegExp object.
(Corresponds to $1, $2, etc. above.) For example,
if /(a+)(+)/, was given, p1 is the match for a+, and p2 for +.

@param offset
The offset of the matched substring within the total string being examined. (For example,
if the total string was "abcd",
and the matched substring was "bc",
then this argument will be 1.)

@param string
The total string being examined.

@returns {*|string}

function replacer(match, p1, p2, p3, offset, string) {     
    console.log("match: " + match);
    console.log("string: " + string);
    //p1 is nondigits, p2 digits, and p3 non-alphanumerics
    console.log("p1: " + p1);
    console.log("p2: " + p2);
    console.log("p3: " + p3);   
    //此處賦值,為了更好的觀察p1,p3的值,位置
    p1 = 1;
    p3 = 3;    
   return [p1, p2, p3].join(" - ");
}
newString = "111abc12345#$*%".replace(/([^d]*)(d*)([^w]*)/, replacer);
console.log(newString);
運(yùn)行結(jié)果:
 * match: 111
 * string: 111abc12345#$*%
 * p1:
 * p2: 111
 * p3:
 * 1 - 111 - 3abc12345#$*%
function replacer2(match, p1, p2, p3, offset, string) {
    console.log("match: " + match);
    console.log("string: " + string);
    // p1 is nondigits, p2 digits, and p3 non-alphanumerics
    console.log("p1: " + p1);
    console.log("p2: " + p2);
    console.log("p3: " + p3);
    return [p1, p2, p3].join(" - ");
}
newString2 = "abc12345xxx#$*%".replace(/([^d]*)(d*)([^w]*)/, replacer2);
console.log(newString2);
運(yùn)行結(jié)果:
 * match: abc12345
 * string: abc12345xxx#$*%
 * p1: abc
 * p2: 12345
 * p3:
 * abc - 12345 - xxx#$*%
function replacer3(match, p1, p2, p3, offset, string) {
    console.log("match: " + match);
    console.log("string: " + string);
    // p1 is nondigits, p2 digits, and p3 non-alphanumerics
    console.log("p1: " + p1);
    console.log("p2: " + p2);
    console.log("p3: " + p3);
    return [p1, p2, p3].join(" - ");
}
newString3 = "1111abc12345xxx#$*%2392039abc12345xxx#$*%".replace(/([^d]*)(d*)([^w]*)/g, replacer3);
console.log(newString3);
運(yùn)行結(jié)果:
 * 第一次匹配

 * match: 1111 
 * string: 1111abc12345xxx#$*%2392039abc12345xxx#$*%
 * p1:
 * p2: 1111
 * p3:

 * 第二次匹配

 * match: abc12345
 * string: 1111abc12345xxx#$*%2392039abc12345xxx#$*%
 * p1: abc
 * p2: 12345
 * p3:


 * 第三次匹配

 * match: xxx#$*%2392039
 * string: 1111abc12345xxx#$*%2392039abc12345xxx#$*%
 * p1: xxx#$*%
 * p2: 2392039
 * p3:


 * 第四次匹配

 * match: abc12345
 * string: 1111abc12345xxx#$*%2392039abc12345xxx#$*%
 * p1: abc
 * p2: 12345
 * p3:

 * 第五次匹配

 * match: xxx#$*%
 * string: 1111abc12345xxx#$*%2392039abc12345xxx#$*%
 * p1: xxx#$*%
 * p2:
 * p3:

 * 第六次匹配

 * match:
 * string: 1111abc12345xxx#$*%2392039abc12345xxx#$*%
 * p1:
 * p2:
 * p3:
 * - 1111 - abc - 12345 - xxx#$*% - 2392039 - abc - 12345 -     xxx#$*% -  -  -  -
match()
function match1() {
    var str = "For more information, see Chapter 3.4.5.1",
        re = /(chapter d+(.d)*)/i,
        found = str.match(re);

    console.dir(found);
}

match1();
運(yùn)行結(jié)果:
 * Array[3]
 * 0: "Chapter 3.4.5.1"
 * 1: "Chapter 3.4.5.1"
 * 2: ".1"
 * index: 26
 * input: "For more information, see Chapter 3.4.5.1"
 * length: 3
 *
 * [input]:
 *         which contains the original string that was parsed
 * [0]:
 *     the first match
 * [1]:
 *     the first value remembered from (Chapter d+(.d)*).
 * [2]:
 *     ".1" is the last value remembered from (.d).
 * ---------------------------------------------------
 */
function match2() {
    var str = "For more information, see Chapter 3.4.5.1",
        re = /(chapter d+(.d)*)/gi,
        found = str.match(re);

    console.dir(found);
}

match2();
運(yùn)行結(jié)果:
 * Array[1]
 * 0: "Chapter 3.4.5.1"
 * length: 1
 *
 * 如果使用了全局匹配g, 則只顯示匹配到的全部字符串。
 * 也沒有input屬性
function match3() {
    var str = "[email protected]",
        re = /(.*)@(.*).(.*)/,
        found = str.match(re);

    console.dir(found);
}

match3();
運(yùn)行結(jié)果:
 * Array[4]
 * 0: "[email protected]"
 * 1: "qbylucky"
 * 2: "gmail"
 * 3: "com"
 * index: 0
 * input: "[email protected]"
 * length: 4
function match4() {
    var str = "[email protected]",
        re = /(.*)@(.*).(.*)/g,
        found = str.match(re);

    console.dir(found);
}

match4();
運(yùn)行結(jié)果:
 * Array[1]
 * 0: "[email protected]"
 * length: 1

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/78085.html

相關(guān)文章

  • JavaScript正則表達(dá)式學(xué)習(xí)筆記(二) - 打怪升級(jí)

    摘要:本文接上篇,基礎(chǔ)部分相對(duì)薄弱的同學(xué)請(qǐng)移步正則表達(dá)式學(xué)習(xí)筆記一理論基礎(chǔ)。正則表達(dá)式標(biāo)志符全局匹配,即找到所有匹配的。方法返回結(jié)果的格式不一致問題這個(gè)問題上文正則表達(dá)式學(xué)習(xí)筆記一理論基礎(chǔ)也有體現(xiàn),這里再單獨(dú)拿來說一說,以加深記憶。 showImg(https://segmentfault.com/img/remote/1460000014261596?w=600&h=338); 本文接上篇...

    Jioby 評(píng)論0 收藏0
  • 正則表達(dá)式之初入江湖

    摘要:拿舉例子只想說明你總會(huì)在一些陰暗的角落遇到正則表達(dá)式,為了到時(shí)候不至于一頭霧水,我們最好簡(jiǎn)單的了解一下正則表達(dá)式的使用。 為什么要學(xué)正則表達(dá)式 很多人對(duì)正則表達(dá)式的認(rèn)知只是在進(jìn)行表單驗(yàn)證的時(shí)候在網(wǎng)上搜一段正則表達(dá)式進(jìn)行copy,實(shí)際工作上好像很難遇到大段的正則表達(dá)式 我第一次看到大量的正則使用是在jQuery源碼中,當(dāng)時(shí)看的頭疼只好草草的看下大概思路不了了之,但是到今天我依然不認(rèn)為這種...

    caige 評(píng)論0 收藏0
  • task0002(一)- JavaScript數(shù)據(jù)類型及語言基礎(chǔ)

    摘要:不過讓流行起來的原因應(yīng)該是是目前所有主流瀏覽器上唯一支持的腳本語言。經(jīng)過測(cè)試,數(shù)字字符串布爾日期可以直接賦值,修改不會(huì)產(chǎn)生影響。再考慮對(duì)象類型為或者的情況。對(duì)于結(jié)果聲明其類型。判斷對(duì)象的類型是還是,結(jié)果類型更改。 轉(zhuǎn)載自我的個(gè)人博客 歡迎大家批評(píng)指正 1. 第一個(gè)頁面交互 這里最需要學(xué)習(xí)的老師的代碼中,每一部分功能都由函數(shù)控制,沒有創(chuàng)建一個(gè)全部變量。且最后有一個(gè)函數(shù)來控制執(zhí)行代碼...

    elarity 評(píng)論0 收藏0
  • 正則表達(dá)式

    摘要:本文內(nèi)容共正則表達(dá)式火拼系列正則表達(dá)式回溯法原理學(xué)習(xí)正則表達(dá)式,是需要懂點(diǎn)兒匹配原理的。正則表達(dá)式迷你書問世了讓幫你生成和解析參數(shù)字符串最全正則表達(dá)式總結(jié)驗(yàn)證號(hào)手機(jī)號(hào)中文郵編身份證地址等是正則表達(dá)式的縮寫,作用是對(duì)字符串執(zhí)行模式匹配。 JS 的正則表達(dá)式 正則表達(dá)式 一種幾乎可以在所有的程序設(shè)計(jì)語言里和所有的計(jì)算機(jī)平臺(tái)上使用的文字處理工具。它可以用來查找特定的信息(搜索),也可以用來查...

    bang590 評(píng)論0 收藏0
  • JavasScript重難點(diǎn)知識(shí)

    摘要:忍者級(jí)別的函數(shù)操作對(duì)于什么是匿名函數(shù),這里就不做過多介紹了。我們需要知道的是,對(duì)于而言,匿名函數(shù)是一個(gè)很重要且具有邏輯性的特性。通常,匿名函數(shù)的使用情況是創(chuàng)建一個(gè)供以后使用的函數(shù)。 JS 中的遞歸 遞歸, 遞歸基礎(chǔ), 斐波那契數(shù)列, 使用遞歸方式深拷貝, 自定義事件添加 這一次,徹底弄懂 JavaScript 執(zhí)行機(jī)制 本文的目的就是要保證你徹底弄懂javascript的執(zhí)行機(jī)制,如果...

    forsigner 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

CoXie

|高級(jí)講師

TA的文章

閱讀更多
最新活動(dòng)
閱讀需要支付1元查看
<