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 关注
- 124 浏览
添加回答
举报