html正则检索替换代码,使用正则表达式替换HTML标记内容

我想要加密HTML文档的文本内容而不更改其布局。内容存储在成对的标记中,如下所示:< span style ...> text_to_get 。我的想法是使用正则表达式来检索(1)并用加密文本(2)替换每个文本部分。我完成了步骤(1),但在步骤(2)中遇到了麻烦。这里是代码我工作:使用正则表达式替换HTML标记内容

private string encryptSpanContent(string text, string passPhrase, string salt, string hash, int iteration, string initialVector, int keySize)

{

string resultText = text;

string pattern = ".*?)>(?.*?)";

Regex regex = new Regex(pattern);

MatchCollection matches = regex.Matches(resultText);

foreach (Match match in matches)

{

string replaceWith = "" + AESEncryption.Encrypt(match.Groups["content"].Value, passPhrase, salt, hash, iteration, initialVector, keySize) + "";

resultText = regex.Replace(resultText, replaceWith);

}

return resultText;

}

这是错行(这使得由最后replaceWith值取代了所有文本)?

resultText = regex.Replace(resultText, replaceWith);

有人能帮我解决这个问题吗?

+1

不要用正则表达式解析HTML一个简单的解决方案。 http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags –

2012-03-19 17:24:18

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值