开发者

Which is the correct shorthand - "regex" or "regexp" [closed]

Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 9 years ago.

Improve this question

Most of us computer programmers are pretty obsessed about correct terminology. I certainly am, especially because sometimes changing just one character in 开发者_JAVA技巧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.


/regexp?/    


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.


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

  • Henry Spencer referred to his famous library as "regexp" as early as 1986. (http://groups.google.com/group/mod.sources/msg/ab37bf1ead7209ec?)
  • The Jargon File listed "regexp (also regex, reg-ex)" as early as 1991. (http://groups.google.com/group/misc.misc/msg/e75ca9cb78220ea0?)
  • JavaScript and Ruby both have Regexp or RegExp in their standard libraries.


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


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.


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.


According to Wikipedia

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


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


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.


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.


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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜