Click here to Skip to main content
15,895,606 members

How to handle Apostrophe

Member 4531085 asked:

Open original thread
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

XML
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.


Waiting for your response.

Thanks
AP
Tags: ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900