开发者

How do you call a string that matches /^\w+$/?

开发者 https://www.devze.com 2023-01-10 07:57 出处:网络
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

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?


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.


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

I personally call it a "word".


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.


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

0

精彩评论

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