js用正则表达式获取html字符串之间的值

<span id="#=LocationId#">#=LocationName#</span>
获取以上所有#=和#之间的值!如(locationId和LocationName

MM们
浏览 1405回答 2
2回答

心有法竹

# python写法&nbsp; &nbsp;正则就是 r"#=(.*?)#"import re# findall找到所有的符合正则的值,以列表的形式返回re.findall(r'#=(.*?)#', s)&nbsp; &nbsp;&nbsp;>>>&nbsp;['LocationId', 'LocationName']

素胚勾勒不出你

const regex = /#=(.*?)#/g;const str = `<span id="#=LocationId#">#=LocationName#</span>`;var result2 = regex.exec(str);while (result2 != null) { &nbsp;console.log(result2[1]) &nbsp;result2 = regex.exec(str);}
打开App,查看更多内容
随时随地看视频慕课网APP