Click here to Skip to main content
12,511,896 members (43,105 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
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>|<.[^>]*>

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
Posted 18-Feb-13 5:36am
Updated 20-Feb-13 21:53pm
v3
Comments
Sergey Alexandrovich Kryukov 18-Feb-13 14:10pm
   
In this regex, you do nothing related to word characters, no you use apostrophe, so what do you want?
—SA
Member 4531085 21-Feb-13 3:53am
   
Hi, 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 something in the existing regex expression to escape all style tag.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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!
  Permalink  
Comments
Member 4531085 21-Feb-13 3:52am
   
Hi, 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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160929.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100