25
2
In this code golf challenge, you will verify hashtags!
#What_your_code_should_do
Input is a string. Output a truthy value if it is a valid hashtag, and a falsy value otherwise.
We define a string as a valid Hashtag if ...
- It starts with a hash (
#
). - It doesn't have a number right after the hashtag (e.g.
#2016USElection
isn't a valid hashtag). - It doesn't have any "special characters" (i.e. any character that isn't an alphabet, underscore (
_
) or a number).
You can assume that the input only contains ASCII characters. (It would be unfair if we did Unicode too.)
#Rules
Basic code-golf rules apply.
#Examples
Truthy:
#
#e
#_ABC
#thisisanunexpectedlylongstringxoxoxoxo
#USElection2016
Falsy:
Hello, World!
#12thBday
#not-valid
#alsoNotValid!
#!not_a_hash
10Is
#
really a valid hashtag? – Adám – 2016-07-18T11:35:04.9001@Adám Why not?? – None – 2016-07-18T11:35:33.777
4Is
#öäü
valid? – chrki – 2016-07-18T12:15:08.980Should the empty string return falsy? Or are we allowed to require at least one character? – owacoder – 2016-07-18T13:00:55.117
7
#
is not a valid hashtag by any system, Facebook or Twitter it also breaks the rules set also im not sure #_ABC is valid again on them but im not certain of that. – Martin Barker – 2016-07-18T13:23:40.9873I assume
an alphabet
means ascii uppercase or lowercase letter? i.e.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
? – Rɪᴋᴇʀ – 2016-07-18T14:14:25.3877A # is not a hashtag. It's a hash. It, followed by a string is what social media networks refer to as a hashtag. It's a tag, which starts with a hash. – i-CONICA – 2016-07-18T15:43:03.847
1Will we receive empty string as an input? – Leaky Nun – 2016-07-18T16:44:10.110
Is printing nothing equals to False? – kenorb – 2016-07-18T22:26:58.177
@LeakyNun No, You won't. – None – 2016-07-19T06:51:12.333
2This is similar to the definition of a valid identifier in many languages. Not sure if abusing
eval
would be possible though. – gcampbell – 2016-07-19T12:40:39.883You should either allow
-
or disallow both-
and_
, in my opinion. – haykam – 2016-07-20T02:58:42.363@Peanut Why? The challenge works perfectly well as is, and
_
is treated as a word character in a lot of contexts while-
almost never is. – Martin Ender – 2016-07-20T07:12:56.613