Help with regular expression
Hi everyone.
I need help to build the string syntax for this particular type of regular expression:
-the string will be length between 4 and 17 chars
-the only chars-set admitted are: A-Z in Uppercase and Lowcase; numbers (0,1,2,3,...9); the dot "." and the underscore "_"
Is there anyone that could help me??
Thanks in advance
Best regards.
Re: Help with regular expression
What language are you using?
Re: Help with regular expression
Re: Help with regular expression
Quote:
Originally Posted by penagate
[a-zA-Z0-9\._]{4,17}
Quick explanation:
[...] signifies a grouping of characters or rules. Useful for times such as these.
a-z, A-Z, 0-9 indicate ranges of characters. Note that on the ASCII table, a and A are 32 characters apart, so a straight a-Z will include more than you actually want. 0-9, fairly self explanatory.
_ speaks for itself. \. on the other hand... the period (.) is a special character in RegEx, and the \ is the escape character. \. is saying "cancel out of the period's special meaning", so the end result is that the period is checked directly.
{4,17} pretty obvious... length specification. A single number defines a maximum value, e.g. {20} would allow anything up to length 20. {4,} will allow any length LONGER than 4.
Re: Help with regular expression
thank you everyone for the suggests and explanations about it.
Best Regards!
Re: Help with regular expression
Quote:
Originally Posted by timeshifter
A single number defines a maximum value, e.g. {20} would allow anything up to length 20.
Actually, {20} means exactly twenty instances. {1,20} would match from one instance to twenty.