2 回答

TA貢獻1876條經驗 獲得超6個贊
好吧,很難以一種方式在正則表達式中做到這一點(至少對我來說是這樣),但你可以分兩步做到這一點。
首先,您從字符串中刪除 html 字符,然后提取之后的單詞。
看看下面。
var text = "00:00:01,514 --> 00:00:04,185 I'm investigating Saturday night's shootings.<i>"
// remove all html char
var noHtml = Regex.Replace(text, @"(<[^>]*>).*", "");
// and now you could get only the words by using @"[a-zA-Z']" on noHtml. You should get "I'm investigating Saturday night's shootings."

TA貢獻1936條經驗 獲得超7個贊
您可以否定環顧四周以斷言不存在由以下not <s 結束的序列,并且不存在后跟 not s 序列的 a 序列。><>
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
string input = @"
<garbage>
Hello world, <rubbish>it's a wonderful day.
<trash>
";
foreach (Match match in Regex.Matches(input, @"(?<!<[^>]*)[a-zA-Z']+(?![^<]*>)"))
{
Console.WriteLine(match.Value);
}
}
}
輸出:
Hello
world
it's
a
wonderful
day
- 2 回答
- 0 關注
- 112 瀏覽
添加回答
舉報