pangloss/vim-javascript — pull request #160 by davidchambers (2014-02-09 21:59:39+00:00)
Title: regexp: fix handling of "]" and "/" in character classes

This change requires some explanation:

```
- skip=+\\\\\|\\/+
+ skip=+\\.\|\[\(\\.\|[^]]\)*\]+
```

First, `\\\\\|\\/` can be generalized to `\\.` Then, we add `\|` and follow it with a pattern to match character classes, `\[\(\\.\|[^]]\)*\]`. A character class begins with __[__ and ends with __]__, so our pattern begins with `\[` and ends with `\]`. This leaves `\(\\.\|[^]]\)*`. Let us preserve our sanity by using the PCRE representation, `(\\.|[^]])*`. This group matches either:

- a backslash followed by any character*, or
- any non-__]__ character.

The asterisk allows the group to match any number of times.

The secret is the `\\.`, which consumes:

- __\\]__ (preventing erroneous termination), and
- __\\\\__ (preventing an escaped __\__ immediately preceding a __]__ from *preventing* termination).

---

\* I assume "any" here means any character other than "\n", though I don't think the distinction is pertinent.