I have an array of keywords in strings:
var keywords = ["Hello World", "or"];
and I have a line of text, e.g.:
var text = "Hello World, Hello World";
I am using RegEx to find the keywords in the text to highlight so that my resulting html would be:
<span class="highlight">Hello World</span>, <span class="highlight">Hello World</span>
However, my RegEx result is returning me this:
[
 0: "or"                          ----------> shouldn't it be "Hello World"?
 index: 7
 input: "Hello World, Hello World"
]
This is my code:
function searchFn(text, keywords) {
  regex = new RegExp(keywords.join("|");
  return regex.exec(text);
}
var text = "Hello World, Hello World";
var keywords = ["Hello World", "or"];
searchFn(text, keywords);
Is my RegEx wrong?
 
    