Back to the lesson

Java[^script]

We have a regexp /Java[^script]/.

Does it match anything in the string Java? In the string JavaScript?

Answers: no, yes.

  • In the script Java it doesn’t match anything, because [^script] means “any character except given ones”. So the regexp looks for "Java" followed by one such symbol, but there’s a string end, no symbols after it.

    alert( "Java".match(/Java[^script]/) ); // null
  • Yes, because the regexp is case-insensitive, the [^script] part matches the character "S".

    alert( "JavaScript".match(/Java[^script]/) ); // "JavaS"