VoiceGem

How to dictate a JavaScript regex literal

A JavaScript regex literal is delimited by slashes, which VoiceGem spaces because the same character is division. Dictating an email pattern returns / ^\S + @\S + / with five spaces to strip, so the honest workflow is to dictate the pattern and clean it in one pass.

A fourteen-word pattern declaration takes about 16 seconds to type and about 5.1 seconds to say. (sources: Dhakal, Feit, Kristensson & Oulasvirta, “Observations on Typing from 136 Million Keystrokes”, CHI 2018, 168,000 participants, 136 million keystrokes; Yuan, Liberman & Cieri, “Towards an Integrated Understanding of Speaking Rate in Conversation”, Interspeech 2006, 2,438 American English telephone conversations (Switchboard corpus). The speech figure is conversational rate, not a measured dictation rate — no such measurement exists.)

What lands in your editor
const emailPattern = / ^\S + @\S + /

This tool runs entirely in your browser. Nothing you type is sent anywhere, stored, or logged.

Step by step

  1. 1

    Open with “slash”

    Say the phrase where the literal starts. The slash keeps its spaces because its table entry serves division, so the delimiter arrives detached.

  2. 2

    Speak the pattern character by character

    Say each metacharacter by name. Anchors, classes and quantifiers are all separate VoiceGem lookups, and letters between them pass through untouched.

  3. 3

    Close with “slash” and the flags

    Say the closing delimiter then the flag letters. The letters are not table phrases so they pass straight through.

  4. 4

    Strip the whitespace

    Remove every space in the pattern before running it. A regex is the one construct where the surrounding spaces are not cosmetic — they change what the pattern matches.

Whitespace in a dictated JavaScript regex is a correctness problem, not a formatting one

Everywhere else on this site, VoiceGem's spacing artifacts are cosmetic and a formatter removes them. Inside a regex literal a space is a character the pattern tries to match, so a dictated pattern that is not cleaned up does not merely look wrong — it matches the wrong strings, silently.

Prettier will not help, because it does not reformat the inside of a regex literal. The practical approach is to dictate the pattern into the tool on this site, strip the spaces there, and paste the result — which is what the demo above is for.

Where the manual way breaks

Typing a short pattern is quick and every character is one keystroke. For \d+ nobody needs to say anything.

Long patterns are where typing stops being reliable rather than stops being fast. A pattern with two capture groups, three quantifiers and an anchor is thirty characters of pure punctuation, and a single wrong one produces a pattern that compiles and matches almost the right thing. Saying it out loud makes each metacharacter a word you can hear yourself get wrong.

Doing this somewhere else? a longer run through the speech-to-code converter, the same thing for dictating JSDoc comments, dictating JavaScript functions specifically, or what changes for naming things in JavaScript by voice.

Common questions

Quantifiers, anchors and delimiters all attach on neither side in VoiceGem's table. Strip every space before running the pattern.

No. Formatters do not reformat the inside of a regex literal, and a space there is a character the pattern tries to match.

No. Letters are not table phrases, so g, i and m pass straight through after the closing delimiter.

Dictate a pattern here, strip the spaces, then paste it.

Open the tool