What is a vim regex for "abcd", where "bc" is optional?

regex, vim

Solution

Solutions: option 1: `ad\|abcd` option 2: `a\(bc\)\=d` option 3: `a\(bc\)\?d` option 4: `\va%[(bc)]d` option 5: `a\%[\(bc\)]d`

Close but not quite: `a\(bc\)\{-\}d` (zero or more; matches abcbcd which is not desired)

+--------+--------------------------+---------------+
| syntax | description              | documentation |
+--------+--------------------------+---------------|
| \|     | logical OR (alternation) | :help /\|     |
| \(bc\) | treat `bc` as a group    | :help /atom   |
| \=     | zero or one occurrences  | :help \=      |
| \?     | zero or one occurrences  | :help \?      |
| \{-\}  | zero or more occurrences |               |
| \%[]   | make the match optional  | :help \%[]    |
| \v     | "very magic": omit \'s   | :help \v      |
+--------+--------------------------+---------------+

Problem

I want to search for occurrences of `ad` and `abcd` where the `bc` is optional. How can I do that? i.e., ``` +-------+----------+ | ad | MATCH | | abcd | MATCH | | abd | NO match | | abbd | NO match | | abced | NO match | | abcbcd| NO match | +-------+----------+ ```

Original source