Groups, captures and backreferences
·predict · hard
Read the optional group
A pattern that pulls a name and an optional title out of a line. For each input, say whether it matches and what each group comes back holding — and be exact about the difference between a group that matched nothing and one that never ran.
//
^()?$
^(+)(?: \((\w*)\))?$
^(\w+)(?:)?$
^(\w+)(?: \(()\))?$
^(\w+)(?: \((*)\))?$
Your prediction
| Input | Matches? | 1 | 2 |
|---|---|---|---|
| ada | — | — | |
| ada (countess) | — | — | |
| ada () | — | — | |
| ada (countess | — | — | |
| (countess) | — | — |
Nothing runs until you have answered every row.