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 46 times
-7
-
Show us what you have tried. – CinCout Jun 14 '17 at 08:07
-
This is basic regex. Have a play around at [Regex101](https://regex101.com/). There is a good reference guide there to get you up and running. – garyh Jun 14 '17 at 08:16
-
Still not getting the answer for it – Sam Jun 14 '17 at 09:16
2 Answers
0
Frank R.
- 1,522
- 16
- 21
-
The difference with zipa's answer is no restriction on the third and following letters – Frank R. Jun 14 '17 at 08:24
-
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
- 26,044
- 6
- 38
- 55