1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2017
    Rep Power

    Exclamation how to replace words with different link for every word in regex

    I have a very long html online book with words I want to link, for example: "Implantogy is a branch of dentistry focused on placing implants into the bone." what i need is:

    Implant=> <a href="#Implant">Implant</a>
    implant=> <a href="#Implant">implant</a>
    implantology=> <a href="#Implant">Implantology</a>
    so I need a list of words that will be search for in a file and surrounded by html code. I've tried RegexBuddy (attachment) but this code is only for one replacement.
  2. #2
  3. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Washington, USA
    Rep Power
    There's a problem
    implantology=> <a href="#Implant">Implantology</a>
    The word "Implant" is nowhere in the source being matched. If the word can't be extracted from the text then it has to be specified in the replacement. And that means a regex for every single word you need to replace.

    A more efficient approach would be to isolate every word in the source you're processing, ignoring common words you don't care about (known as stop words) like "the" or "and", and search your dictionary list. If the dictionary is sorted then you can perform a binary search - the result is O(n log m), saying "n" is the source and "m" is the dictionary, doing it this way versus O(n m) with a regex. You can also keep a cache of search results, since specific words are likely to appear more than once if at all, and get some even better performance that way.

IMN logo majestic logo threadwatch logo seochat tools logo