This is a follow-up of Find multiple keywords within a dictionary.
My questions are...
The first is: I believe this matches words that are not whole. Like if short is in my dictionary it matches the word shortly. How would I stop this?
And the second not so important but would be nice is: How would I make it so it only matches once per content? So short doesn't get defined twice within the same content area.
Thanks!
I have implemented the following additional requirements:
shortly
when looking forshort
(becauseshortly
is a different word)Example input: key=
foo
, replacement=bar
, content=foo foo
.Output:
bar foo
(only the firstfoo
is replaced).Demo: http://jsfiddle.net/bhGE3/3/
Usage:
dictionary
. Each key will be used only once.content
. A new string will be created, based on this string.replacehandler
function. This function is called at each match. The return value will be used to replace the matched phrase.The default
replacehandler
will return the dictionary's matching phrase. The function should take two arguments:key
anddictionary
.replaceOnceUsingDictionary(dictionary, content, replacehandler)
content
to the user.Code: