My code is unable to detect the usage of operators along with non-english characters:
const OPERATOR_REGEX = new RegExp(
/(?!\B"[^"|“|”]*)\b(and|or|not|exclude)(?=.*[\s])\b(?![^"|“|”]*"\B)/,
'giu'
);
const query1 = '(Java or "化粧" or 化粧品)';
const query2 = '(Java or 化粧 or 化粧品)';
console.log(query1.split(OPERATOR_REGEX));
console.log(query2.split(OPERATOR_REGEX));
https://codepen.io/thewebtud/pen/vYraavd?editors=1111
Whereas the same code successfully detects all operators on regex101.com using the unicode flag: https://regex101.com/r/FC84BH/1
How can this be fixed for JS?
or, etc. if it is preceded with"(not after a word char) that is followed with zero or more chars other than",“and”, right? Then your pattern must have looked like/(?<!\B"[^"“”]*)\b(and|or|not|exclude)(?=.*\s)\b(?![^"“”]*"\B)/. That is, the first lookaround must be a negative lookbehind.[ '(', 'Java', 'or', '"化粧"', 'or', '化粧品', ')'], or possibly this with quotes removed:[ '(', 'Java', 'or', '化粧', 'or', '化粧品', ')']