Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用正则表达式从html文件中获取希伯来语字符串/单词?_C#_Regex - Fatal编程技术网

C# 如何使用正则表达式从html文件中获取希伯来语字符串/单词?

C# 如何使用正则表达式从html文件中获取希伯来语字符串/单词?,c#,regex,C#,Regex,在表格1的顶部,我做了: private static readonly Regex AnyWordRegex = new Regex(@"((?<word>[a-zA-Z]{4,}))", RegexOptions.Singleline | RegexOptions.Compiled); 本例中的OriginalHtmlFilePath包括带有希伯来语单词的html文件 这是StripHtml: public static string StripHtml(string html

在表格1的顶部,我做了:

private static readonly Regex AnyWordRegex = new Regex(@"((?<word>[a-zA-Z]{4,}))", RegexOptions.Singleline | RegexOptions.Compiled);
本例中的OriginalHtmlFilePath包括带有希伯来语单词的html文件

这是StripHtml:

public static string StripHtml(string htmlString)
        {
            return StripHtmlRegex.Replace(htmlString, @"|");
        }
之后,我看到HTML包含希伯来语单词。 然后我在构造函数中执行以下操作:

_words = ExtractWords(strippedHtml);
_单词列表

private static List<string> ExtractWords(string text)
        {
            MatchCollection matchCollection = AnyWordRegex.Matches(text);
            return (from Match match in matchCollection select match.Groups[1].Value).ToList();
        }
私有静态列表提取字(字符串文本)
{
MatchCollection MatchCollection=AnyWordRegex.Matches(文本);
返回(从matchCollection中的Match选择Match.Groups[1].Value).ToList();
}
完成单词提取后,我发现列表中的单词只包含英语单词。 大约608个单词只有英语。但是我在这个案例中工作的网站是www.walla.co.il或www.ynet.co.il,这是一个希伯来语网站


如果我在cnn.com或foxnews.com的任何英文网站上工作,一切正常。

你可以使用
\p{L}
而不是
[a-zA-Z]
来匹配所有字母表中的所有字母,或者
[\p{IsHebrew}a-zA-Z]
更具体地说。

你可以使用
\p{L}
而不是
[a-zA-Z]
匹配所有字母表中的所有字母,或者更具体地说,
[\p{IsHebrew}a-zA-Z]

Anirudh那么,如果没有正则表达式,如何从html文件中获取所有单词?我试过htmlagilitypack,但到目前为止还没有找到合适的方法。@HaimKashi:您使用Html Agility Pack提取文本,然后使用正则表达式从文本中提取单词。Anirudh那么,如果没有正则表达式,我如何从Html文件中获取所有单词?我试过htmlagilitypack,但到目前为止还没有找到合适的方法。@HaimKashi:您可以使用Html Agility Pack提取文本,然后使用正则表达式从文本中提取单词。
private static List<string> ExtractWords(string text)
        {
            MatchCollection matchCollection = AnyWordRegex.Matches(text);
            return (from Match match in matchCollection select match.Groups[1].Value).ToList();
        }