国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

javascript - 正則的截取匹配問題求助

瀏覽:168日期:2023-03-10 13:59:07

問題描述

srcmainwebappstaticca7ecd95-aa95-4da8-b369-92b66b566958icon.png

想截取從static開始的字符串,請問正則該如何寫?感謝

也就是staticca7ecd95-aa95-4da8-b369-92b66b566958icon.png

另外由于url前半段可能會變動,所以最好還是用正則的好

問題解答

回答1:

var str=’srcmainwebappstaticca7ecd95-aa95-4da8-b369-92b66b566958icon.png’;alert(str.replace(/^.*?(static.*?)$/ig, ’$1’));回答2:

split(’static’)[1] 這樣的嗎? 還是必須用正則?

回答3:

str.slice(str.search(/static/));

回答4:

正則應(yīng)該用 static.* 就可以,下面是參考代碼

const regex = /static.*/g;const str = `srcmainwebappstaticca7ecd95-aa95-4da8-b369-92b66b566958icon.png`;let m;while ((m = regex.exec(str)) !== null) { // This is necessary to avoid infinite loops with zero-width matches if (m.index === regex.lastIndex) {regex.lastIndex++; }// The result can be accessed through the `m`-variable. m.forEach((match, groupIndex) => {console.log(`Found match, group ${groupIndex}: ${match}`); });回答5:

’srcmainwebappstaticca7ecd95-aa95-4da8-b369-92b66b566958icon.png’.split(’static’)[1]

回答6:

’srcmainwebappstaticca7ecd95-aa95-4da8-b369-92b66b566958icon.png’.match(/static.*/)// Output: [ 'staticca7ecd95-aa95-4da8-b369-92b66b566958icon.png']

這個問題的亮點:

javascript - 正則的截取匹配問題求助

標(biāo)簽: JavaScript
相關(guān)文章:
主站蜘蛛池模板: 东光县| 汾西县| 建昌县| 金昌市| 沙田区| 凤城市| 揭西县| 孝感市| 汾西县| 辽宁省| 钦州市| 菏泽市| 揭西县| 临沂市| 建水县| 锡林郭勒盟| 新竹县| 盐城市| 改则县| 南昌县| 黄梅县| 鹤庆县| 南城县| 朝阳区| 奉化市| 铜梁县| 广河县| 织金县| 那曲县| 北宁市| 大安市| 望江县| 丹阳市| 松桃| 忻州市| 额敏县| 乐都县| 柏乡县| 瑞丽市| 潼关县| 临泽县|