C# Corner Annual Conference 2015
Forum guidelines
Regular Expressions
Posted By Anand N on 10 Apr 2013

Can you please explain me this regular expression?


[a-zA-Z0-9]{8,10} means any alphabets or digits 8 to 10 characters.


(?!^[0-9]*$) or  (?!^[a-zA-Z]*$)  what are these expressions?

Thanks in advance

  • 0
  • 0
Re: Regular Expressions
Posted By Vulpes on 10 Apr 2013   Accepted Answer
Those are what are called 'negative lookahead' expressions. 

(?!exp) is the template for these where 'exp' is some regular expression.

Negative lookaheads mean that the match must not be followed by 'exp'.

A negative lookahead is like a sneak preview - after it's taken place, matching continues as though the sneak preview had not taken place.

So (?!^[0-9]*$) means first check that the text doesn't contain only digits and  (?!^[a-zA-Z]*$) means then check that it doesn't contain only letters.

Having done that ^([a-zA-Z0-9]{8,10})$ then goes back to the beginning of the text and checks that it contains between 8 and 10 letters and digits.

C# Corner Annual Conference 2015


Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.