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

您的位置:首頁技術文章
文章詳情頁

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

瀏覽:140日期: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:

正則應該用 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 - 正則的截取匹配問題求助

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 庆云县| 文水县| 吉林省| 安图县| 斗六市| 武山县| 嘉禾县| 南川市| 兰考县| 元氏县| 永福县| 逊克县| 垫江县| 昆山市| 石城县| 中卫市| 师宗县| 法库县| 宿州市| 林口县| 民县| 兴国县| 元江| 哈巴河县| 赤城县| 阳新县| 海门市| 遵化市| 泰和县| 广河县| 连州市| 如东县| 南丹县| 曲阳县| 上虞市| 红桥区| 宁城县| 河南省| 禄丰县| 泽州县| 开封县|