2 つの言語が混在する多くのテキスト行を含むこのドキュメントがあり、次のようになります: (単語 עשמ と טקסט を見てください)
<a href="http://www.example.co.il/search/index.aspx?sQuery=ID:עשמ@111/13&CaseType=טקסט" />
ターゲット:
私がやろうとしているのは、「他の言語」のテキスト部分をエンコードされたものに置き換えることです。
問題:
「他の言語」のテキストの最初の文字しか取得できません。
私は正規表現のこのパターンを使用しています:
((href=\"http://.+?sQuery=[^\"]*)([א-ת]+)([^\"]*\"))+?
これはメソッドの完全なコードです:
string[] files = Directory.GetFiles(@"C:\Test", "*.html", SearchOption.AllDirectories);
foreach (string file in files)
{
string fileContent = File.ReadAllText(file, Encoding.GetEncoding(1255));
fileContent = fileContent.Replace("windows-1255", "utf-8");
Regex hrefRegex = new Regex("((href=\"http://.+?sQuery=[^\"]*)([א-ת]+)([^\"]*\"))+?");
fileContent = Regex.Replace(fileContent,hrefRegex.ToString(), delegate(Match match)
{
string textToEncode = match.Groups[3].Value;
string encodedText = HttpUtility.UrlEncode(textToEncode, new UTF8 Encoding(false)).ToUpper();
return match.Groups[2].Value + encodedText + match.Groups[4].Value;
});
File.WriteAllText(file + "_fix.html", fileContent, new UTF8Encoding(false));
}
私は何を間違っていますか?
そして、正規表現パターンを更新して、href 内のすべての「他の言語」部分を見つけるにはどうすればよいですか。