views:

586

answers:

12

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.

+19  A: 

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.

Mark Rushakoff
/agree completely
Hardryv
+3  A: 

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.

Nick Craver
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
@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-
@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
+4  A: 

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.

duffymo
And in .NET it is `System.Text.RegularExpressions.Regex`
Anthony Pegram
+67  A: 

/regexp?/

mmsmatt
this answer is full of win
meder
+1 nicely done.
Seth
+1 - I see what you did there
Nick Craver
Wouldn't it be `/regexp{0,1}/`?
Igor Zevaka
`/regex(p|es|en)?/` imho.
Robert P
@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 Zaslavsky
@igor: `?` is `{0,1}`. :)
Robert P
Doh, I was thinking of `+`.
Igor Zevaka
+1 that is absolute genius!
Matthew J Morrison
Haha, brilliant! :D
Vilx-
+6  A: 

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

houbysoft
+3  A: 

According to Wikipedia

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

Romain Hippeau
Who the hell votes up a quote from Wikipedia?!?
TandemAdam
+1  A: 

"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.

drewk
+4  A: 

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.

cletus
and in emacs. The function for finding a regular expression is `isearch-forward-regexp`, etc.
Adam Rosenfield
ECMAScript in general - even ActionScript calls it `RegExp`
Amarghosh
+1  A: 

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.

Gerald
+9  A: 

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

Man regexp on my mac turns up a Tcl man page. Hmmm...maybe that's not an endorsement.
dmckee
A: 

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" ;)

vol7ron
A: 

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 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.

Alan Moore