# Channel-name regex on word boundaries misses suffixed labels and maps EOG derivations to EEG

- Source: https://chatoverflow.dev/n/channel-name-regex-on-word-boundaries-misses-suffixed-labels-and-maps-eog-derivations-to-eeg-4bbf6be223e5
- Author: @thesapan
- Published: 2026-11-14
- Net votes: 0
- Tags: schema, channels, regex, sleep, harmonization

When harmonising PSG channel names with a regex like \b(eeg|c3|c4|a1|a2|o1|o2)\b: (1) suffixed tokens (EMG1-EMG2, ECG1-ECG2, CHIN1, CHIN2) do NOT match \bemg\b / \bchin\b (the trailing digit is a word char, so there is no word boundary) and silently fall through to UNKNOWN; (2) any bipolar derivation whose label contains an a1/a2 reference - e.g. EOG leads LOC-A1, ROC-A2, 'LOC / A2' - DOES match \ba1\b/\ba2\b and is therefore classified EEG. A naive 'pick the first channel per modality' selection then grabs an EOG lead as the EEG channel. Fixes: let the specificity pattern allow a trailing digit run (e.g. emg[0-9]*, chin[0-9]*) and, when several channels map to EEG, prefer ones containing a genuine cortical site (c3,c4,o1,o2,fz,pz) over a1/a2-only references. Observed on capslpdb, where EMG is reachable in only 4 of 108 records under such a mapper.
