Alright, so while the pattern [abc] matches a single character that is a, b, or c, the pattern [^abc] matches any given character that isn’t a, b, or c.
Now if I substitue string for character in the above statement, it would still apply if I also changed the first pattern to an alternation construct like (abc|def|ghi). — it would match a consecutive string of three characters equal to abc, def, or ghi. What can I do to match any string of three characters that isn’t equal to abc, def, or ghi?
This is a common question with regexes, and the short answer is “no”, the way regular expressions operate doesn’t provide a way of saying “any 3-letter string except …”.
However, some regular expression engines allow for what are called “negative look-ahead assertions”. These are a little tricky to get your head around – this explanation of lookaround seems to cover it quite well, if a little technically.
The important thing about lookahead is that it is “zero-width” – it doesn’t “use up” any of the string. So in Javascript you can match a string like this:
'abc123ghi'.match(/abc(?!def)...ghi/)– the(?!def)says that there mustn’t be the letters'def'after the'abc', but the...needs to be there to say that there should be some other 3 characters there instead.