[Question]
  [
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](/questions/tagged/code-golf "show questions tagged 'code-golf'") rules apply.
# #Examples
Truthy:
```
#
#e
#_ABC 
#thisisanunexpectedlylongstringxoxoxoxo
#USElection2016
```
Falsy:
```
Hello, World!
#12thBday
#not-valid
#alsoNotValid!
#!not_a_hash
```
  
[Answer]
## [Retina](https://github.com/m-ender/retina), 12 bytes
```
^#(?!\d)\w*$
```
Prints `1` for hashtags and `0` otherwise.
[Try it online!](http://retina.tryitonline.net/#code=JShHYApeIyg_IVxkKVx3KiQ&input=I1VTRWxlY3Rpb24yMDE2CiMKI3RoaXNpc2FudW5leHBlY3RlZGx5bG9uZ3N0cmluZ3hveG94b3hvCiNIYXNodGFnX29yX25vdAojX2hhc2gKIzEydGhCZGF5CkhlbGxvLCBXb3JsZCEKIzIwMTZVU0VsZWN0aW9uCiMj) (The first line enables a linefeed-separated test suite.)
Not much to explain here, this is quite a literal implementation of the definition: `^` and `$` are just anchors ensuring that the match covers the entire string, `#` checks that the string starts with a `#`, `(?!\d)` ensures that the next character *isn't* a digit (without advancing the regex engine's position), `\w*` checks that we can reach the end of the string with zero or more letters, digits or underscores.
By default, Retina counts the number of matches of the given regex, which is why this gives `1` for valid hash tags and `0` otherwise.
[Answer]
## Perl, 22 bytes
**21 bytes code +1 for `-p`**
```
$_=/^#([a-z_]\w*)?$/i
```
Prints 1 if it's a valid hashtag, empty string otherwise.
### Usage
```
perl -pe '$_=/^#([a-z_]\w*)?$/i' <<< '#'
1
perl -pe '$_=/^#([a-z_]\w*)?$/i' <<< '#_test'
1
perl -pe '$_=/^#([a-z_]\w*)?$/i' <<< '#1test'
```
Saved 2 bytes thanks for [Martin Ender](https://codegolf.stackexchange.com/users/8478/martin-ender) (and another 4 using his [lookaround method](https://codegolf.stackexchange.com/q/85621))
---
## Perl, 18 bytes
**17 bytes code +1 for `-p`**
Using Martin's lookaround this can be much shorter!
```
$_=/^#(?!\d)\w*$/
```
[Answer]
# JavaScript (ES6), 25 bytes
```
s=>/^#(?!\d)\w*$/.test(s)
```
```
F = s => /^#(?!\d)\w*$/.test(s)
input.oninput = () => result.innerHTML = input.value ? F(input.value) ? '\ud83d\udc8e' : '\ud83d\udca9' : '\ud83d\udcad';
```
```
#input, #result {
  vertical-align: middle;
  display: inline-block;
}
#input {
  line-height: 2em;
}
#result {
    font-size: 2em;
}
```
```
<input id="input" type="text"/> <span id="result">&#x1f4ad</span>
```
[Answer]
# C, 80 bytes
Function `f()` takes the string as an argument and modifies `int *b` to either 1 or 0 to indicate truthy/falsy.
```
f(char*p,int*b){for(*b=(*p==35)&&!isdigit(p[1]);*p;++p)*b&=isalnum(*p)||*p==95;}
```
If the string always has at least one character (i.e. never an empty string), a byte can be shaved off for 79 bytes:
```
f(char*p,int*b){for(*b=(*p==35)&&!isdigit(p[1]);*++p;)*b&=isalnum(*p)||*p==95;}
```
[Answer]
# Python 3, 41 bytes
```
import re
re.compile('#(?!\d)\w*$').match
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 55 bytes
```
"#"|h"#",?b@lL'(eE,@A:"1234567890":"_"c'eE),@A:"_"ce~hL
```
This uses no regex.
### Explanation
```
Main predicate, Input (?) is a string
  "#"                           ? = "#"
|                             Or
  h"#",                         First character of ? is "#"
  ?b@lL                         L is the rest of the chars of ? lowercased
  '(                            It is not possible for any char of L that...
    eE,                           Call this char E
    @A:"1234567890":"_"c          Concatenate the lowercase alphabet with the digits and "_"
    'eE                           E is not a member of that concatenated string
   ),                           
   @A:"_"c                      Concatenate the lowercase alphabet with "_"
   e~hL                         One char of that concatenated string is the first char of L
```
[Answer]
## Python 3, ~~103~~ 93 bytes
```
all((c=='_'or c.isalpha()*i>0)^(i<1and'#'==c)^(c.isdigit()*i>1)for i,c in enumerate(input()))
```
The `#` being `True` killed me here, I had to enumerate the string to avoid an index error on the single character input.
[Answer]
## PowerShell v2+, 25 bytes
```
$args-match'^#(?!\d)\w*$'
```
Using [Martin's regex](https://codegolf.stackexchange.com/a/85621/42963), just wrapped up in PowerShell's `-match` operator coupled with the input `$args`. For truthy/falsey values, this will return the string itself on a match (a truthy value) or nothing on a non-match (a falsey value). This is because when a comparison operator is applied against an array, it [returns anything](https://codegolf.stackexchange.com/a/745/42963) that satisfies that operator.
A couple examples (wrapped in a `[bool]` cast to make the output more clear):
```
PS C:\Tools\Scripts\golfing> [bool](.\hashtag-or-not.ps1 '#2016Election')
False
PS C:\Tools\Scripts\golfing> [bool](.\hashtag-or-not.ps1 'Hello, World!')
False
PS C:\Tools\Scripts\golfing> [bool](.\hashtag-or-not.ps1 '#')
True
PS C:\Tools\Scripts\golfing> [bool](.\hashtag-or-not.ps1 '')
False
PS C:\Tools\Scripts\golfing> [bool](.\hashtag-or-not.ps1 '#USElection2016')
True
```
[Answer]
# Mathematica, ~~52~~ ~~46~~ 43 bytes
Saved ~~6~~ 9 bytes due to [@MartinEnder](http://ppcg.lol/users/8478).
```
StringMatchQ@RegularExpression@"#(?!\d)\w*"
```
Function. Takes a string as input, and returns `True` or `False` as output. Pretty simple, just matches against the regex `/#(?!\d)\w*/`.
[Answer]
# [Dyalog APL](http://goo.gl/9KrKoM), ~~22~~ 20 [bytes](http://meta.codegolf.stackexchange.com/a/9429/43319)
Without RegEx:
```
{0≤⎕NC 1↓⍵,⎕A}∧'#'=⊃
```
-2 thanks to ngn
[Answer]
# Python 2, 79 bytes
```
lambda x:x=='#'or(1>x[1].isdigit())&x[1:].replace('_','').isalnum()&('#'==x[0])
```
First golfing attempt. Ungolfed version:
```
def f(x):
    if x == '#':
        return True
    else:
        return x[0]=='#' and x[1:].replace('_','').isalnum() and not x[1].isdigit()
```
[Answer]
# Octave, ~~37~~ ~~56~~ ~~54~~ 43 bytes
Thanks to @LuisMendo for removing 8 bytes!
```
@(s)s(1)==35&(isvarname(s(2:end))|nnz(s)<2)
```
Not very golfy, but very built-inny.  
Edit: The original code accepted strings with no leading '#'. I guess I should have stuck with regex.
Test suite on [ideone](http://ideone.com/ihx7a5).
[Answer]
## Python3 - 156 128 bytes
```
lambda n:n=="#"or(n[0]=="#")*all(any([47<ord(c)<58,64<ord(c)<91,ord(c)==95,96<ord(c)<123])for c in n[1:]+"0")*~(47<ord(n[1])<58)
```
A solution that doesn't use regex. 0 is falsey and every other value is truthy.
Thanks to @LeakyNun for saving bytes!
[Answer]
# Lua, ~~59~~ ~~55~~ 54 bytes
## Code
```
s=arg[1]print(load(s:sub(2).."=0")and s:sub(1,1)=="#")
```
## How it works:
1. Check if the rest of the characters can be a valud Lua identifier (identifiers in Lua follow the same rules as hashtags.)
2. Check if the first character is a `#`.
Takes input from the command line. Prints `true` if the string is a valid hashtag, otherwise, it prints `nil`.
[Answer]
# Google Sheets, 30 bytes
An anonymous worksheet function that takes input from the cell `A1` checks it against the RE2 expression and outputs the result to the calling cell.
```
=RegexMatch(A1,"^#([a-z_]\w*)?
```
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), 18 bytes
Code:
```
¬'#Qs¦A«¬d_sDžjKQP
```
Uses the **CP-1252** encoding. [Try it online!](http://05ab1e.tryitonline.net/#code=wqwnI1FzwqZBwqvCrGRfc0TFvmpLUVA&input=I1Byb2dyYW1taW5nX1B1enpsZXNfYW5kX0NvZGVfR29sZg).
[Answer]
# Sed 19 + 2 = 21 bytes
```
/^#([a-z_]\w*)?$/Ip
```
This filters out all non-hashtags and outputs valid hashtags.
Run as `sed -rn "/^#$|^#[a-z]\w*$/Ip"`. Quit with `Ctrl` + `D` (send EOF).
[Answer]
# GNU grep, 15 + 2 = 17 bytes
```
grep -Ei '^#([a-z_]\w*)?$'
```
### Test:
```
$ echo '#
#e
#_ABC
#thisisanunexpectedlylongstringxoxoxoxo
#USElection2016
Hello, World!
#12thBday
#not-valid
#alsoNotValid!' | grep -Ei '^#([a-z_][a-z0-9_]*)?$'
```
Output:
```
#
#e
#_ABC
#thisisanunexpectedlylongstringxoxoxoxo
#USElection2016
```
[Answer]
# Python 3, 97 Bytes 70 Bytes 56 Bytes
```
lambda x:s=x[2:];b=x[1];all(x!="#",[x[0]=="#",any[b.isalpha(),"_"in b],any[s.isalnum(),"_"in s]])
```
(Code changed) Human readable
```
x=input()
if x[0]=="#" and x[1].isalpha() and str(x)[2:].isalnum():
    print(True)
else:
    print(False)
```
[Answer]
## Pyke, 19 bytes
```
\#.^It,!It\_D-PRkq|
```
[Try it here!](http://pyke.catbus.co.uk/?code=%5C%23.%5EIt%2C%21It%5C_D-PRkq%7C&input=%23)
Quick fix for tonight
[Answer]
# Ruby, 16 + ~~3~~ 1 (`n` flag) = ~~19~~ 17 bytes
Uses `0` as truthy and `nil` as falsy.
```
p~/^#(?!\d)\w*$/
```
Run it as `ruby -ne 'p~/^#(?!\d)\w*$/'`. Thanks to @manatwork for fixing the bash error when running the program.
[Answer]
# [Standard ML](http://www.mlton.org/), ~~121~~ ~~118~~ 107 bytes
```
(fn#"#"::a=>(fn x::r=>x> #"@"andalso List.all(fn#"_"=>1=1|c=>Char.isAlphaNum c)a|e=>1=1)a|e=>1=0)o explode;
```
[Try it online!](https://tio.run/##TVDLasMwEDzXX6EolxiSEOfQg41M41DooeQS2h76MIutxoK11lhKcSD/7kpWCkVI2h3NaKQxLa5atKTHcfGt53zO0xRE7mo2pGkv8iFnc/7AQdeAhtizMnYNiBO55CJPRHKtRL5voF8rs8OugcO5ZVUMVzmd/hWbmJgcOqRaZuMPILPSWCZYCx1bdL3SlhHzvkbk5ot/aB47oCDCtaWjdYST65WNs8ir3VS1k79Hd@7RS7/KsJW7Yh8q2yijDOizdsaysrLGC5I@mem2gcII3JfjIzqKIr3dJPf8M7go/d/nSSLSkr1Rj/UsyJKtbYoaLqHTZFeTILQ@sQPZV4/c@DNHKaFswDTeY8pgUmRRyMB//IbfzLPxFw "Standard ML (MLton) – Try It Online")
Functional solution without using regex. Declares an anonymous function which is bond to the implicit result identifier `it`. 
```
> val it = fn : string -> bool    
- it "#valid_hash";
> val it = true : bool
```
[Answer]
# Excel VBA, 54 bytes
Anonymous VBE immediate window function that takes input from cell `[A1]`, checks if the value of the cell matches the `Like` pattern, and outputs as `Boolean` to the VBE immediate window
```
?Not[Left(A1,2)]Like"[#]#"And[A1]Like"[#][_a-zA-z0-9]*
```
[Answer]
# [Haskell](https://www.haskell.org/), 79 bytes
```
import Data.Char
f(a:r)=a=='#'&&r==""||r!!0>'@'&&all(\c->c=='_'||isAlphaNum c)r
```
[Try it online!](https://tio.run/##bY9Ba8IwFMfPzadII9gWrKiHHQaRqRvssHkRt8OU8mirCUuTkKRDod@9S42HHfYC7@U9fv9/XhjY71qIvueNVsbhZ3Aw3TAw6JTCo8koUJqMkvHYUEpI15k4ni2TJz8AIdJDmS9LDxRJ13G7EprBtm1wmZn@BwSvMMVfKCIjMhlyHUqxWm/CzTFuuQXZyvqi69LVlbgKJc/WGS7PFxVOYPe7F@ERruRiNn8gR8Tl3yde/SfUBH8qI6o4KOYLx9YVXEMnlctvgtCCsGqr3McwufOxRwooGFjm7VEDXHrzSqGoAf2OU@2XcniKTxm@GaFIt27nzJsk@RDkH/C@ZP8L "Haskell – Try It Online")
[Answer]
# C#, 92 bytes
```
s=>s[0]=='#'&s.Length>1&&(s[1]<48|s[1]>57)&s.Skip(1).All(x=>char.IsLetterOrDigit(x)|x=='_');
```
C# lambda (`Predicate`) where input is a `string` and output is a `bool`.
[Try it online!](https://dotnetfiddle.net/3DxbYm)
[Answer]
## Lua, 39 bytes
```
print(arg[1]:match("^#[%a_][%a_%d]*$"))
```
Straightforward copypasta of match description. Outputs falsy `nil` if not hashtag, outputs truthly hashtag back otherwise.
Can be shortened for one more byte by using `find` if outputing list of two values (which is truthly) doesn't break rules.
[Answer]
## Clojure, ~~130~~ ~~135~~ 132 bytes
* +5 bytes to deal with an NPE that happened when the string consisted of only a hashtag.
* -2 bytes by using `Character/isLetterOrDigit`.
```
(fn[s](let[[h & r]s n(map int r)](and(= h\#)(not(<= 48(or(first n)0)57))(every? #(or(Character/isLetterOrDigit^long %)(= 95 %))n))))
```
Ungolfed:
```
(defn hashtag? [s]
  (let [[h & r] s
        codes (map int r)]
    (and (= h \#)
         (not (<= 48 (or (first codes) 0) 57))
         (every?
           #(or (Character/isLetterOrDigit ^long %)
                (= 95 %))
           codes))))
```
[Answer]
# Java 8, ~~57~~ ~~54~~ 28 bytes
```
s->s.matches("#(?!\\d)\\w*")
```
Port of [Martin Ender's Retina answer](https://codegolf.stackexchange.com/a/85621/52210) to save a few bytes and match added test cases.  
Not that [`String#matches`](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#matches(java.lang.String)) always matches the entire String, so no need for `^...$`.
[Try it here.](https://tio.run/##hY4xT8NADIX3/go3XRJEI9qBpQJEERILXSrEQBBy70xz5eKLck5phPLbw9FkRZHtwfL3nt8Bjzh3JfFBf3XKovfwjIZ/JgCGhapPVASbvxVg55wlZFDxVirDe/DJKhzaMKG9oBgFG2C4gc7Pb31aoKicfBzN4rtplukky74voqRb9Yqy3tmgGIRHZzQU4ffg/vYOmPSPt40XKlJXS1qGk1iOOVVx9ETWukt4dZXV0yg5p/mfnr1sHy0pMY6XV4vrcV5y441HrplOZRCSto11vPfnfCfX17jPYin5WmMzTo4TNI583K8fBqqdtN0v)
]