正则表达式在向后看和向前看之间只获取字母



我试图只从"130b2c94-22ba-4584-b18a-899eb4be045d">

<input type="hidden" name="logonInfo.forceAuthn" value="false" id="sSignOnauthenticateUser_logonInfo_forceAuthn"/>
<input type="hidden" name="logonInfo.inResponseTO" value="_130b2c94-22ba-4584-b18a-899eb4be045d" id="sSignOnauthenticateUser_logonInfo_inResponseTO"/>
<input type="hidden" name="logonInfo.issuerUrl" 

我试过了

(?<=name="logonInfo.inResponseTO" value="_).*(?=" id="sSignOnauthenticateUser)

提取我需要的字符串,但我需要进一步将其分解为只有字母

使用DOM解析器。这将可靠地解释HTML并给你一个DOM。

然后使用CSS选择器查询查找具有value属性的input元素,该属性的值以下划线开头。

最后使用正则表达式删除找到的值中的所有非字母:

const html = `
<input type="hidden" name="logonInfo.forceAuthn" value="false" id="sSignOnauthenticateUser_logonInfo_forceAuthn"/>
<input type="hidden" name="logonInfo.inResponseTO" value="_130b2c94-22ba-4584-b18a-899eb4be045d" id="sSignOnauthenticateUser_logonInfo_inResponseTO"/>
<input type="hidden" name="logonInfo.issuerUrl" >`;
const doc = new DOMParser().parseFromString(html, "text/html");
for (const input of doc.querySelectorAll("input[value^=_]")) {
const letters = input.value.replace(/[^a-z]/gi, "");
console.log(input.name, ":", letters);
}

最新更新