Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Tooltip word replacement

Last post 11-20-2008, 7:16 AM by gralov. 5 replies.
Sort Posts: Previous Next
  •  11-14-2008, 2:30 AM 48287

    Tooltip word replacement

    Hi

    I'm currently working on a ASP.NET project where i want to replace sertain words with a link ex. "all your base are belong to us, is a cool phrase" if I want to replace the letter a as in "a cool phrase" with <a href="/#mylink">a</a> i want the new string to look like this, "all your base are belong to us, is <a href="/#mylink">a</a> cool phrase".
    This means that if the word or letter is a part of a longer word, the letter or word shouldn't be relpaced ex. "all" this a shouldn't be replaced and allso if the letter a allready is lagged up as a link ex. "<a href="/#mylink">a</a>", it shouldn't be replaced either and not if its in the href attribute ex href="a".

    I've been searching this forum for two days now without result unfortunalty, i've found a varity of regex that does allmost the thing i need.
    Please can someone help me with this.

    Best regards
    Patrik

  •  11-14-2008, 3:34 AM 48292 in reply to 48287

    Re: Tooltip word replacement

    See this similar previous question for a possible start:

    http://regexadvice.com/forums/thread/45309.aspx


  •  11-14-2008, 4:17 AM 48293 in reply to 48292

    Re: Tooltip word replacement

    Thanks for your reply.

    I've been playing around with that regex and found that this
    \b(?si)(searchword)(?![^<>]*</a>)(?=([^<>]*<[^>]+>[^<>]*)+$|[^<>]*$)\b
    does allmost what i want, if i have a string sush as "i'm trying to find this searchword but not these searchwords <a href="searchword">searchword</a>" it finds searchword but not searchwords and non of those combined with the link.
    But for some reason it ignores cases, so if i have Searchword and searchword it replaces both, and it doen't matter what RegexOptions i set. I need it to be Case sensitive.
    Could you help me with this please

  •  11-16-2008, 5:44 PM 48359 in reply to 48293

    Re: Tooltip word replacement

    If you want case sensitivity, then change the "(?si)" to "(?s)". At the moment you are turning ON the 'ignore case' option which is making all of the subsequent pattern case insensitive.

    Susan

  •  11-16-2008, 6:17 PM 48361 in reply to 48293

    Re: Tooltip word replacement

    Although the (?i) might be in there for the HTML tag </a> closing just in case some href closing tag appears as </A>, so you might consider:

    \bsearchword(?![^<>]*</[aA]>)(?=(?:[^<>]*<[^>]+>[^<>]*)+$|[^<>]*$)\b

    I don't see the use of the . in the pattern so (?s) would have no effect, I have removed it from the pattern.  I have also removed the extra capture groups from the pattern since they didn't seem to have any use.


  •  11-20-2008, 7:16 AM 48559 in reply to 48361

    Re: Tooltip word replacement

    Thanks for your reply and all the help, the expression seems to work fine now.
View as RSS news feed in XML