47

The term regular expression is often shortened to regex. What is the correct pronunciation of the g in regex?

Is it like the g1 in gallium, or is it like the g2 in giraffe? I’ve heard it said both ways.


1.   IPA /g/
2.  IPA /dʒ/

tchrist
  • 134,759
  • 6
    Since it's /ɡ/ in regular, it's /ɡ/ when it shortens to regex. Changes like this take place in speech, not spelling. Spelling rules do not affect speech; rather, speech affects spelling rules. Occasionally. – John Lawler Dec 14 '12 at 15:20
  • 4
    As in all cases where a portmanteau is formed from two words, the pronunciation is preserved in the portmanteau -- the sounds are identical in the original words and the new one. – Kris Dec 14 '12 at 15:20
  • @JohnLawler Second thoughts: Could there be exceptions to what I stated just now in the above comment of mine? – Kris Dec 14 '12 at 15:21
  • 1
    There can always be local variants; if somebody in a company decides it's cool to pronounce it /'rɛdʒɛks/, it might catch on there. But that's close to being a pun with rejects, so you want to make sure the stressed vowel is mid lax instead of high tense. – John Lawler Dec 14 '12 at 15:24
  • The post coleopterist linked to seems to indicate that there isn't one correct answer to this. Is that correct? – Anirudh Ramanathan Dec 14 '12 at 15:25
  • 9
    @Kris: in my experience, portmanteau words regularly change the pronunciation of the individual parts. Certainly, when my boss pronounced favicon according to your rule, our web designer didn't have a clue what he was talking about. – Marthaª Dec 14 '12 at 15:28
  • 3
    @coleopterist, I think that is, indeed, a duplicate; but I think this is a nice illustration of why it's actually good to have duplicates, because this question's title is much more likely to match what someone is searching for than the older question's title. – Marthaª Dec 14 '12 at 15:33
  • I wonder if there's a regexp to detect duplicate questions. [Pp]ortmanteau+ – rajah9 Dec 14 '12 at 15:44
  • 1
    @rajah9 English would need to be a Chomsky Type-3 grammar for that to be possible ;) – Anirudh Ramanathan Dec 14 '12 at 15:47
  • English ain't no Type-3 Regular language ;-) – rajah9 Dec 14 '12 at 16:00
  • 5
    It's pronounced Ray-hacks, of course! What? – Kaz Dragon Dec 14 '12 at 16:05
  • 1
    @Kris: Interesting question. The only possible exception I could think of was Wikipedia; I usually hear the i's in "Wiki" pronounced like "kiwi", but I often hear the second vowel of "Wikipedia" pronounced with more of a schwa (ə) sound. But I don't know if that example would even count, because (1) it's just a subtle vowel shift, and (2) it's a controversial pronunciation as well. – J.R. Dec 14 '12 at 16:08
  • 1
    @Cthulhu: yes, there isn't one correct answer. I disagree with John Lawler: I pronounce it /'rɛdʒɛks/, and I think most of my friends and colleagues do too. – Colin Fine Dec 15 '12 at 00:56
  • @Marthaª As you must have learnt from the accepted answer there by now, you boss was right and your design person was not equipped enough to understand it. /fav-ee-can/ ? ah, yes, must be teen-slang. That reference question helps to know what disasters can happen when pronunciation changes in a portmanteau word. – Kris Dec 15 '12 at 14:24
  • @Marthaª I thought you said "but I think this is a nice illustration of why it's actually good to have duplicates," then why vote to close, and be the first at it? :) – Kris Dec 15 '12 at 14:35
  • @Kris: because it's still a duplicate, of course. It should be kept around as a signpost to the original question, but there's really no need for it to sit around collecting more answers. – Marthaª Dec 15 '12 at 16:33
  • I pronounce it /rɪ'gɛks/. Sounds cooler and easier to roll the tongue – phuclv Oct 13 '18 at 16:16

4 Answers4

43

On page 27 of Mastering Regular Expressions, Jeffrey Friedl states:

Instead, I normally use "regex." It just rolls right off the tongue ("it rhymes with "FedEx," with a hard g sound like "regular" and not a soft one like in "Regina") and it is amenable to a variety of uses like "when you regex ...," "budding regexers," and even "regexification."

So, if you are looking for an authoritative answer, the above is it.

In a footnote, Friedl also adds:

You might also come across the decidedly unsightly "regexp." I'm not sure how one would pronounce that, but those with a lisp might find it a bit easier.


FWIW, I pronounce it with the soft g simply because it sounds better to mine ears. However, most of the programmers I know do employ the hard g.

coleopterist
  • 31,031
20

Sweet reason clearly dictates, as an abbreviation of regular, it should be pronounced /ɹɛ.ɡɛks/. However, I've heard it said thousands of times and far more often than not, it is pronounced /ɹɛ.dʒɛks/. Dunno why, but there it is.

9

It matters how you link the word to Regular Expression.

1) RegEx => /ɹɛɡ.ɛks/ => You're new to Regular Expression - the word. You're capturing it with two words Reg and Ex.

2) regex => /ɹɛdʒɛks/ => You're very familiar with the word Regular Expression - your mind doesn't remember the full word when you say regex. You think it a whole word to Regular Expression.

So, if you're pronouncing it with the hard g sound, then your mind still captures the full word. And if you're pronouncing it with soft g sound, then your mind doesn't capture the full word but you just capture the word regex as full word.

Bhojendra Rauniyar
  • 205
  • 1
  • 3
  • 7
4

I've always heard rejeks or even reejeks. Never heard any other pronunciation. It doesn't lend itself very well to extending. I've been regexing is weird. I never say "regex" to the uninitiated or even "regular expression". Stick instead with word or character pattern.

Chris
  • 104