views:

86

answers:

4

Strings that match /^\w+$/ are quite common. For example many authentication systems use that pattern to validate usernames. I'm wondering if a term exists that identifies this kind of strings.

I've been thinking of the term "alphanumeric" but is a string alphanumeric if it contains an underscore?

+4  A: 

I do not think that it is a good idea to give it a potentially confusing name. Alphanumeric could be misunderstood. If you need to refer to it, for example in your documentation, define it with an unique name like 'username_pattern', and refer to that definition of yours whenever you talk about it.

relet
+4  A: 

From perldoc perlre: '\w Match a "word" character (alphanumeric plus "_")'.

I personally call it a "word".

hlynur
That's an interesting suggestion but wouldn't it be confusing to call "123" a word?
Emanuil
If '123' is a username, for example, it's a word, even though it is made of numerals.
Gregg Lind
+1  A: 

Personally, I’d call it “a string that matches ^\w+$” if my audience knows what this means. That is probably the most succint “name” that doesn’t significantly sacrifice accuracy. If I had to say it, I might call it “a non-empty string containing only word characters”, but once again I need to assume that my listener(s) know the technical meaning of word character.

If you want to come up with an English name for it, you are necessarily going to sacrifice a lot of accuracy and end up with something much more vague than the hard and well-defined regular expression — especially if your audience is not technical and/or does not recognise the term as a technical term with this precise meaning.

Timwi
A: 

I'm with hlynur, (some) POSIX character classes call this a word.
So it would be consistent to call this a word.

Nils
But then that would mean that you don't mind calling `123` a word.
Emanuil
Well, it _may_ be a word, then again it may be not. :-) What I tried to explain was: In another place there Is a name for this thing and it's a reasonable one -- why not use it?
Nils