VoiceGem

How to dictate a Python raw-string regex

Python patterns live in raw strings, which dictate better than JavaScript literals because the r prefix and the quotes both bind correctly. Brace quantifiers are the cost: a date pattern returns r"\d { 4 } -\d { 2 }" with four spaces to remove.

A sixteen-word pattern assignment costs about 18 seconds typed against about 5.9 seconds spoken. (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
date_pattern = r"\d { 4 } -\d { 2 }"

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

Step by step

  1. 1

    Name the pattern with a casing command

    Say “snake case date pattern equals”. The casing run ends at the equals, which is where the string literal begins.

  2. 2

    Say “r double quote” to open the raw string

    Speak the prefix letter then the quote. The letter passes through VoiceGem untouched and the quote binds forward onto it, giving r" with no gap.

  3. 3

    Say each metacharacter by name

    Speak “backslash d”, “open brace”, the count, “close brace”. Backslash classes come out clean because the backslash attaches on both sides.

  4. 4

    Remove the brace spaces

    Strip the whitespace around every quantifier before compiling. Braces keep their spaces because the same characters open code blocks.

Python raw strings dictate better than JavaScript literals, and braces are why they still need work

Two of the three parts land correctly. The r prefix passes through as an ordinary letter, and the double quote binds on both sides so the string closes up around the pattern — which is more than a slash-delimited literal manages.

Brace quantifiers are the remaining cost. VoiceGem's brace entry keeps its spaces because it also opens code blocks, so every {4} and {2,5} in a dictated Python pattern arrives spaced and has to be closed before re.compile sees it.

Where doing it by hand breaks down

Short patterns are fast to type and Python's re module is forgiving about how you build them. A two-character class needs no help.

Date and identifier patterns with several counted quantifiers are the case worth speaking. Four braces, two escaped classes and a literal separator is a dense line where the count inside a brace is easy to get wrong by one, and hearing yourself say “open brace four close brace” into VoiceGem is a check that reading the character does not give you.

Doing this somewhere else? our speech-to-code converter, the same thing for dictating Python docstrings, dictating Python functions, step by step, or what changes for naming things in Python by voice.

Common questions

Yes. The letter r is not a VoiceGem table phrase so it passes through, and the double quote binds forward onto it with no gap.

The brace entry keeps its spaces because the same characters open code blocks. Close the gaps before compiling the pattern.

Yes. The backslash attaches on both sides, so \d and \w arrive with no space between the two characters.

Dictate a date pattern and count the braces you need to close.

Open the tool