问题描述
大家好,
我想匹配我的数据库中的单词,为此我使用正则表达式忽略html标签我的表达式是
Hi All,
I want to match words from my database and for that i use regular expression to ignore html tags my expression is "
<script.*/*>|</script>|<.[^>]*>
。但它不会处理像撇号这样的词语,它不是,等等。
下面是我用来返回单词的方法
". But it dont handle words comes with apostrophe like Dont''t, It''s and so on.
Below is the Method that i am using to return the words
private string HighlightSearchKeyWords(string TextToHighlight, string TextAsDiscription, string text)
{
string ProcessedText = text;
var pattern = keywordPattern(TextToHighlight);
string TagExpression = "<script.*/*>|</script>|<.[^>]*>";
Regex reg = new Regex("(" + TagExpression + ")|(" + pattern + ")", RegexOptions.IgnoreCase | RegexOptions.Multiline);
MatchReplacement = "<span id='" + TextToHighlight.ToString() +"_Span"+ "' style='background-color: yellow; cursor: hand;' onmouseover='javascript:SaveMouseOVerWords(this,this.id)' onmouseout='javascript:HideContent()' mytitle='" + TextAsDiscription + "'>$1</span>";//onmouseout='javascript:HideContent()'
ProcessedText = reg.Replace(ProcessedText, new MatchEvaluator(MatchEval));
return ProcessedText;
}
但是这个方法也返回带撇号的单词,我想忽略那些单词
请建议在我现有的表达式中添加什么,以便他也处理撇号。
注意:
But this method return the words with apostrophe also and i want ignore those words
Please suggest what should add in my existing expression so that he handle apostrophe as well.
NOTE:
My problem is i have read all the browser content in a string and now i am trying match list of words with the browser content, when the word match i highlight that word, but word like "abstract or absolute" which come with style tag also get highlight. i want to escape those words that come inside HTML style tag. In order to escape all tag inside script tag i have written "<script.*/*>|</script>|<.[^>]*>" . so i want to add someting in the existing regex expression to escape all style tag.
等待你的回复。
谢谢
AP
Waiting for your response.
Thanks
AP
推荐答案
但是这个方法也返回带有撇号的单词,我想忽略那些单词
请建议在我现有的表达式中添加什么,以便他也处理撇号。
注意:
But this method return the words with apostrophe also and i want ignore those words
Please suggest what should add in my existing expression so that he handle apostrophe as well.
NOTE:
My problem is i have read all the browser content in a string and now i am trying match list of words with the browser content, when the word match i highlight that word, but word like "abstract or absolute" which come with style tag also get highlight. i want to escape those words that come inside HTML style tag. In order to escape all tag inside script tag i have written "<script.*/*>|</script>|<.[^>]*>" . so i want to add someting in the existing regex expression to escape all style tag.
等待你的回复。
谢谢
AP
Waiting for your response.
Thanks
AP
这篇关于如何处理撇号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!