i am having trouble with jquery code of the "jquery_token_inpuy"

return template.replace(new RegExp(
    "(?![^&;]+;)(?!<[^<>]*)(" + value + ")(?![^<>]*>)(?![^&;]+;)", "g"
), highlight_term(value, term));

i have this error : SyntaxError: Invalid regular expression: / Nothing to repeat.

What is the problem?

有帮助吗?

解决方案

You could use a routine to "quote" all the meta-characters. Something like this would be a start:

function regexSanitize( str ) {
  return str.replace(/([.+*?:\[\](){}|\\])/g, "\\$1");
}

then:

return template.replace(
  new RegExp(
    "(?![^&;]+;)(?!<[^<>]*)(" + 
    regexSanitize(value) + 
    ")(?![^<>]*>)(?![^&;]+;)", "g"), 
  highlight_term(value, term)
);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top