I want regex with at least 2 characters start with any alphabet or any digit not matters.But It can accept - and _ . Ex : ABD , Abc_123 , 12, A-_ , A1 etc.
Asked
Active
Viewed 50 times
2 Answers
0

Frank R.
- 1,732
- 18
- 21
-
The difference with zipa's answer is no restriction on the third and following letters – Frank R. Jun 14 '17 at 08:24
-
yes...i saw it but I think it will take other special chars too. as @, # – Sam Jun 14 '17 at 09:03
0
This should do the trick:
[\w-]{2,}
But, if you want to ignore words that have special characters, you can use this:
(?<=\s|^)([\w-]{2,})(?=\s+|$)

zipa
- 27,316
- 6
- 40
- 58