문제

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