如何处理撇号 [英] How to handle Apostrophe

查看:89
本文介绍了如何处理撇号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想匹配我的数据库中的单词,为此我使用正则表达式忽略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

推荐答案

1 < ; / span > ; // onmouseout ='javascript:HideContent()'
ProcessedText = reg.Replace(ProcessedText,new MatchEvaluator(MatchEval));
返回ProcessedText;
}
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


没有明显的理由说明你给我们的正则表达式不能用于撇号 - 它只是寻找标签,并忽略文本。因此,除非你使用正则表达式用空格替换标签,否则输出不太可能包含不要,它是等等。



你确定这是正则表达式的问题吗?通常,数据库和撇号的问题是由串联字符串形成SQL查询而不是使用参数化查询引起的,其中插入或更新行的尝试失败并显示SQL错误消息(或者在极端情况下删除数据库)。 />


检查您输入数据库的实际数据,并检查您的操作方式。我怀疑正则表达式是红鲱鱼!
There is no obvious reason why the regex you have given us would not work with apostrophes - all it does is look for tags, and ignore text. So unless you use the regex to replace the tags with blanks, the output is very unlikely to contain "don''t", "it''s" and so on anyway.

Are you sure it''s the regex that''s the problem? Normally a problem with databases and apostrophes is caused by concatenating strings to form an SQL query instead of using parametrized queries, where the attempt to insert or update a row fails with an SQL error message (or in extreme cases deletes your database).

Check the actual data that you are feeding to the DB, and check how you are doing it. I suspect that the regex is a red herring!


这篇关于如何处理撇号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆