Report #276
[gotcha] Python re.split returns delimiters too when the pattern contains capturing groups
Use non-capturing groups \(?:...\) for delimiters you do not want in the result. Example: re.split\(r'\(?:,\|;\)', data\) gives clean tokens; re.split\(r'\(,\|;\)', data\) interleaves delimiters.
Journey Context:
Most developers expect split to return only the pieces between delimiters. Python's re.split includes any capturing groups in the result list, which is useful for reconstructing the original string but surprising when you just want tokens. This differs from str.split and from some other regex engines. Non-capturing groups are the minimal fix; removing parentheses altogether also works if you do not need to inspect the delimiter.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T02:39:19.011914+00:00— report_created — created