Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

regex101.com says it works, by returning multiple matches, only one of which has a group 1.

But I don't what environments return multiple matches from one evaluation.



The matches must be non-overlapping, because Tarzan is contained in "Tarzan". Therefore, the input

  "Tarzan", she said.
contains two matches for the regex

  "Tarzan"|Tarzan.
The first match is at character 0, for the "Tarzan" branch of the regex. The second match is at character 1 for the Tarzan branch of the regex.

If matches can be overlapping, then the inner Tarzan is matched in spite of being surrounded in quotes, and the capture register is bound and all.

This works not as a property of the regex (what it matches), but the regex combined with a scanning algorithm that extracts non-overlapping matches.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: