Q:

Match an expression with no << or ]]

I need to match the pattern only if << or >> or ]] or [[ is not present in the string.
If any of these special characters are present the match should be zero else it should match.
For example, I have an expression Stackoverflow which should return as a match but if I have Stack]]over<<flow I should not get a trueful response. The following pattern unfortunately does not work:
/^(\[\[)|(\]\])|(\<\<)|(\>\>)

Thank you

A:

Use the following regular expression and negate the result:
<<|>>|\]\]|\[\[

Here is a live example:

var regex = /<<|>>|\]\]|\[\[/;
var strings = [
  "Stackoverflow",
  "Stack]]over<<flow"
];

for(var i=0; i<strings.length; i++) {
  console.log(!regex.test(strings[i]));
}

If you can't negate the result (like when using Angular's ng-pattern), you can also use a negative lookahead:
^((?!<<|>>|\]\]|\[\[).)*$

Here is a live example:

var regex = /^((?!<<|>>|\]\]|\[\[).)*$/;
var strings = [
  "Stackoverflow",
  "Stack]]over<<flow"
];

for(var i=0; i<strings.length; i++) {
  console.log(regex.test(strings[i]));
}

