Reputation: 91
I'm struggling with writing correct RegExp, which matches words with and without numbers/dashes/underscore Correct words:
stackoverflow
stackoverfloW1
stack-overflow
stack_overflow1
etc.
I've came up with this one: \w+(-\w+)+([A-Za-z0-9_\-])
, but it matches only words with dash, so stack-overflow
works, but not stackoverflow
Upvotes: 0
Views: 161
Reputation: 43169
In addition to my comment, here an answer as well:
([-_a-zA-Z0-9]+)
# will match dash, underscore, a-z, A-Z an numbers
See the mentionned regex 101 demo. However, look into @stribizhev's comment as well as he is far more experienced than I am (considering his reputation he's here all the time...).
Upvotes: 1