(?.*?)>(?.*?)(a1)"; 例如,如果有""在 a1 中,在标题变量之后 ""应该成为。 最-6ren">
gpt4 book ai didi

c# - 正则表达式模式中的相同变量

转载 作者:太空宇宙 更新时间:2023-11-03 13:52:24 25 4
gpt4 key购买 nike

我想在正则表达式模式中使用相同的变量。

string Pattern = "<li.*?class=\".*?item\".*?>.*?<a.*?href=\"(?<link>.*?)\">(?<a1>.*?)>(?<title>.*?)(a1)";

例如,如果有"<span>"在 a1 中,在标题变量之后 "<span>"应该成为。

最佳答案

如果您需要引用以前捕获的组

使用

\index//where index is the group number

\k<name>//where name is the name of the group

所以在你的情况下它应该是 \k<a1>


此外正则表达式不用于解析 HTML

使用htmlagilitypack

关于c# - 正则表达式模式中的相同变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13330871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com