VoiceGem

How to dictate a PHP preg_match pattern with delimiters

PHP patterns are unusual: the delimiter characters live inside the quoted string, so a dictated pattern has two nested layers of punctuation. Saying the whole call returns preg_match('/ ^ abc / i', $input) with four spaces to strip before it runs.

A seventeen-word preg_match call costs about 20 seconds to type and about 6.2 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
preg_match('/ ^ order -\d + / i', $input)

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

Step by step

  1. 1

    Say the function name with underscores

    Speak “preg underscore match”. The underscore attaches on both sides, so the three parts of the name arrive joined with no spaces.

  2. 2

    Open the quoted string

    Say “open paren single quote”. Both bind tightly in VoiceGem's table, so the literal starts flush inside the bracket.

  3. 3

    Say the delimiter, then the pattern, then the delimiter and flags

    Speak “slash”, the pattern, “slash”, then the flag letters. The delimiters are ordinary characters inside the string, and they keep their spaces.

  4. 4

    Strip four spaces, not two

    Remove whitespace around both delimiters as well as inside the pattern. PHP's nested structure means more cleanup than a language whose delimiters are syntax.

PHP nests its delimiters inside the string, which doubles the cleanup

Most languages make the regex delimiter part of the syntax — a JavaScript literal's slashes and a Go raw string's backticks are both outside the pattern. PHP puts the delimiter inside a quoted string, so a dictated pattern has quote characters and delimiter characters, and only the quotes bind correctly.

The practical result is more spaces to strip per pattern than in any other language on this list. Dictating a PHP pattern through VoiceGem is still faster than typing one for anything long, but the cleanup step is not optional and this page would be misleading if it implied otherwise.

Where the manual way breaks

PhpStorm highlights regex inside preg_match calls and offers a pattern tester, which is genuine tooling support that dictation does not replace.

Function name underscores are the small win. PHP's regex functions are preg_match, preg_replace, preg_match_all and preg_split, and each underscore is a Shift-hyphen mid-word. Saying “preg underscore match underscore all” builds the whole name from three lookups that all bind on both sides.

Doing this somewhere else? speech-to-code converter, on your own input, dictating PHP functions, step by step, dictating shell regular expressions, step by step, or how dictating Go regular expressions works.

Common questions

The delimiters live inside a quoted string rather than being syntax, so both the delimiters and the quantifiers keep their spaces. Expect four to strip rather than two.

Yes. The underscore attaches on both sides, so preg_match_all arrives fully joined from three separate lookups.

Yes. Say “hash” instead of “slash” for a pattern containing slashes. VoiceGem emits whichever character you name.

Dictate a preg_match call and count the four spaces to remove.

Open the tool