148

Most of us computer programmers are pretty obsessed about correct terminology. I certainly am, especially because sometimes changing just one character in a word can drastically change its meaning.

So... what is the correct shorthand for "regular expression"? Is it "regex" or "regexp"? On the internet I see both uses, although "regex" seems to be more popular, and the tag list here on SO also includes just "regex". But plenty of people also use "regexp" in their questions.

18
  • 5
    I believe that the one which is easiest to pronounce wins - "regex" beats "regexp" there by a mile. This happens all the time in human languages. That is just my opinion. Commented Jun 17, 2010 at 1:05
  • 12
    I have honestly never seen it referred to as regexp. Not once in my entire life before this instant. Commented Jun 17, 2010 at 1:06
  • 4
    Historically, you are of course correct. The word "regex" is a contraction of the words "regular expression". But the things that we call regular expressions are completely different than the things we call regex. For example: regular expressions are designed to be extremely simple and elegant. I can write down the full syntax and semantics of regular expressions in 4 lines each. In fact, I don't even need full lines, just 4 bullet points each are enough. In contrast, the syntax for regexp literals in the ECMAScript5 specification takes up an entire page ... Commented Jun 17, 2010 at 19:38
  • 2
    This reminds me of another 'important' question: "Is it pronounced 'car' or 'char'?"
    – Ash
    Commented Jun 18, 2010 at 5:50
  • 2
    This question appears to be off-topic because it is about terminology and not programming.
    – Toto
    Commented Sep 28, 2013 at 9:11

13 Answers 13

669
/regexp?/    

4
  • 1
    Wouldn't it be /regexp{0,1}/? Commented Jun 17, 2010 at 1:24
  • 9
    @Igor: that's precisely what ? means in a regular expression, {0,1}. True, some regexp? engines don't support the question mark but they suck ;-) Anyway Perl does, and it's the closest thing to a "standard" for regular expression syntax.
    – David Z
    Commented Jun 17, 2010 at 1:27
  • 10
    This is not the answer to the question asked.
    – Azat
    Commented Aug 8, 2014 at 23:29
  • 6
    @Azat Yes, it is. It perfectly says whichever is ok!
    – Déjà vu
    Commented Sep 13, 2016 at 2:25
76

Googlefight says regex wins, 685000 to 289000 (which is about 2.37:1).

Also, regexp is strange to say out loud because there are so few (if any?) words that end in a "-ksp" sound, but there are plenty of words that end in a "-ecks" sound.

4
  • 9
    In World of Warcraft, people go out to gain some "exp" (short for "experience points"). So saying "exp" is neither hard nor does it sound weird. It is all simply a matter of how used the speaker is to that word.
    – Shi
    Commented Sep 24, 2012 at 22:32
  • 9
    I'd pronounce "exp" as "ex-pee" - I don't play WoW... Commented Aug 26, 2016 at 11:25
  • 3
    I like the answer, but I prefer the pronounciation of regexp. Saying simply regex is lacking, because it does not account all the consonants in the beginning. Usually abbreviations should do that, eg. constant should be const, not con. Commented Jun 21, 2017 at 12:33
  • @Shi Warcraft players almost always read or write "exp". Commented Apr 30, 2018 at 16:27
31

They are both OK. "regex" is more common, but "regexp" has been used more widely than the other answers here indicate. Some examples:

1
  • 2
    Man regexp on my mac turns up a Tcl man page. Hmmm...maybe that's not an endorsement. Commented Jun 17, 2010 at 2:12
17

regex is shorter; therefore, better :) Also, it is easier to pronounce.

13

The accepted shorthand is "regex".

"Regexp" is only used, in my experience, in the context of Javascript where the object representing a regular expression is actually called RegExp.

4
  • 4
    and in emacs. The function for finding a regular expression is isearch-forward-regexp, etc. Commented Jun 17, 2010 at 3:45
  • 3
    ECMAScript in general - even ActionScript calls it RegExp
    – Amarghosh
    Commented Jun 17, 2010 at 3:58
  • 3
    Ruby too: ruby-doc.org/core-1.9.3/Regexp.html
    – qerub
    Commented Feb 22, 2013 at 20:48
  • 2
    Well, in the original memo of QED, where Dennis Ritchie and Ken Thompson introduced the brand new feature of regular expressions (in the context of text editing), they wrote: "In subsequent discussion, "<regexp>" will denote a regular expression."
    – Sz.
    Commented Feb 3, 2018 at 16:41
7

I think "regex" is more common (e.g., Java package java.util.regex). If 10,000 Elvis fans can't be wrong, then I'd vote for that on the strength of numbers.

2
  • 2
    And in .NET it is System.Text.RegularExpressions.Regex Commented Jun 17, 2010 at 1:19
  • It's also Regex in Swift.
    – Míng
    Commented Sep 5, 2022 at 2:35
7

According to Wikipedia

In computing, regular expressions, also referred to as regex or regexp, ...

3
  • 13
    Who the hell votes up a quote from Wikipedia?!?
    – Adam Harte
    Commented Jun 17, 2010 at 3:56
  • 13
    @Adam Harte: Who the heck votes up rhetorical questions? Commented Jul 27, 2011 at 23:28
  • 1
    @Andrew haha, it's actually a "question statement question"
    – Adam Harte
    Commented Jul 28, 2011 at 1:46
6

"regex" is more common and what is used in the Perl FAQ. Google gives 4.5 million hits for "regex" and 3.6 million for "regexp." Wikipedia uses both.

What do you prefer? I don't think anyone will think of you badly if you use them interchangeably.

1
  • 7
    Interestingly enough "perldoc perlre" (that describes regular expressions in perl), says "regex" everywhere but references "Regexp Quote-Like Operators" in perlop. "perldoc perlop" is a little confused ans says both, though mostly "regex". "perl -le 'print ref(qr/x/)'" prints out "Regexp". So perl is confused, I'd say. Commented Jan 17, 2013 at 15:56
6

I think it's time to quit thinking in terms of shorthands or abbreviations. The regexes that we use in our daily tasks are a different breed entirely from the regular expressions of computer science or formal language theory. This is why Larry Wall and other prominent members of the Perl community have preferred "regex" for years: to call them RegExp or RegEx, or even RE, suggests a relationship that no longer applies.

4

I would say it's "regex", this is based on my own experience, how I've heard it, and the community discussion here.

I can't find it at the moment, but this discussion was on meta over tags on SO, which is why this is the only question tagged "regexp", the rest (8441 and counting) are tagged "regex".


Just a side thought here: does it matter which is "correct?" Think about the purpose here, why do you use any word? To communicate. To a certain degree, it doesn't matter what's correct or not, it matters which one you can effectively communicate to more people. I would say you could easily argue to use an incorrect term, if that's what the majority of your audience uses, since communication is your goal.

4
  • 1
    The reason there are no questions tagged "regexp" is because some of us keep removing that tag or replacing it with "regex" (as I just did here). We don't need two tags with the same meaning, and "regex" has the edge in terms of users' preferences (though that may be just because it's shorter).
    – Alan Moore
    Commented Jun 17, 2010 at 3:59
  • @Alan - yes, but don't you think that in this case "regexp" was ALSO a good choice, because the question is about comparing the two?
    – Vilx-
    Commented Jun 17, 2010 at 7:31
  • 1
    @Vlix- You could just as easily argue that neither tag is appropriate, since the question is really about terminology, not regexes. But the responses seem to show that "regex" is the winner anyway, so why don't we just stick with that?
    – Alan Moore
    Commented Jun 17, 2010 at 9:30
  • 3
    UPDATE: This Q/A ran its course before the "tag synonyms" feature was implemented here at StackOverflow. Now tags like regexp and regular-expression are automatically converted to regex.
    – Alan Moore
    Commented Sep 28, 2013 at 0:36
3

Both are fine for written discourse, though you probably don't want to say "regexp" out loud too often ;)

For use in code, I think regexp is probably clearer. Especially if you use capitalization such as RegEx/RegExp. An Ex suffix is often used to indicate an extended version of a simpler function... i.e. CreateWindow/CreateWindowEx in the Windows API, so RegExp might be a little less ambiguous as far as readability of code goes.

0
3

I have also heard/read:

reg-exp

And some people prefer regex because the plural regexes is "nicer"! (in addition to reasons explained by other answers).

.NET regex : System.Text.RegularExpressions.Regex

JavaScript regexp : RegExp

1
  • 2
    Or n.pl. Regexen.
    – Walf
    Commented Feb 19, 2017 at 12:24
-1

I prefer "re", but it depends on the language. JavaScript lists it as "RegExp", whereas most other languages just call it "RegEx."

When googling, go with the shorter version. But in forums, use "re" ;)

Not the answer you're looking for? Browse other questions tagged or ask your own question.