-7

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.

Sam
  • 1
  • 4

2 Answers2

0

(Updated)

(?=[-\w]{2}).*

Online test, https://regex101.com/r/JcUaBz/2

Frank R.
  • 1,732
  • 18
  • 21
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