c#正则表达式如何有这个匹配

本文关键字:正则表达式 | 更新日期: 2023-09-27 18:05:16

请帮我解决这个问题,非常感谢

string=
"
<span id="thread_aaaa" class="tsubject">
    <a href="viewthread.php?tid=12343245&amp;extra=page%3D1"> 
        WHAT I WANT TO GET1 
    </a>
</span>
<span id="thread_bbbb" class="tsubject">
    <a href="viewthread.php?tid=65456342&amp;extra=page%3D1">
        WHAT I WANT TO GET2
    </a>
</span>
"

我需要得到WHAT i WANT TO GET1, WHAT i WANT TO GET2等的值

我正在使用:( " < span id='"thread_)(.+?)< /a>< /span>"),但不工作,帮助

c#正则表达式如何有这个匹配

对于给定的新示例字符串,这将找到它们:

string str = @"
< span id=""thread_aaaa"" class=""tsubject"" >< a href=""viewthread.php?tid=12343245&extra=page%3D1"" > WHAT I WANT TO GET1 < /a >< / span>
< span id=""thread_bbbb"" class=""tsubject"">< a href=""viewthread.php?tid=65456342&extra=page%3D1"" >WHAT I WANT TO GET2</a>< /span>";
Regex regex1 = new Regex(@"href.*>(.*)< *'/a");
var matches = regex1.Matches(str);
foreach (var m in matches)
{
    var match = (Match) m;
    Console.WriteLine(match.Groups[1].Value.Trim()); // write the value to the console "pattern"
}
/*
Output:
WHAT I WANT TO GET1 
WHAT I WANT TO GET2
*/

您要查找的正则表达式是:

(?<=aaa)(.*)(?=bbb)

//匹配aaa和bbb之间的任何字符