扫码关注官方订阅号
<xml xmlns="http://www.w3.org/1999/xhtml"> <block type="variables_get" id="EaezE9)%*e^B{Olq7?Le" x="147" y="34"></block> </xml>
请问如何获取这段字符串中的id?额,这是一段字符串
认证0级讲师
正则的话,试一下用match,其实也就是要识别到字符串 id="EaezE9)%*e^B{Olq7?Le",然后提取出引号里面的字符串
id="EaezE9)%*e^B{Olq7?Le"
var t = `<xml xmlns="http://www.w3.org/1999/xhtml"> <block type="variables_get" id="EaezE9)%*e^B{Olq7?Le" x="147" y="34"></block> </xml>`; var res = t.match(/id\s*="([^"]*)"/); console.log(res&&res[1])
var span = document.createElement("span"); span.innerHTML = `<xml xmlns="http://www.w3.org/1999/xhtml"> <block type="variables_get" id="EaezE9)%*e^B{Olq7?Le" x="147" y="34"></block> </xml>`; var block= span.getElementsByTagName('block')[0]; var id = block.getAttribute("id");
https://zhidao.baidu.com/ques...
var str='<xml xmlns="http://www.w3.org/1999/xhtml"><block type="variables_get" id="EaezE9)%*e^B{Olq7?Le" x="147" y="34"></block></xml>'; var reg = /.*id\=\"([^ \"]*).*/gi; reg.exec(str)[1];
正则正解
(/id="([^"]*)"/)
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
正则的话,试一下用match,其实也就是要识别到字符串
id="EaezE9)%*e^B{Olq7?Le",然后提取出引号里面的字符串https://zhidao.baidu.com/ques...
正则正解