PDA

Click to See Complete Forum and Search --> : Help with regular expression


motogpdesmo16
Nov 4th, 2007, 09:17 AM
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.

Hack
Nov 5th, 2007, 05:54 AM
What language are you using?

penagate
Nov 5th, 2007, 05:55 AM
[a-zA-Z0-9\._]{4,17}

timeshifter
Nov 5th, 2007, 05:06 PM
[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.

motogpdesmo16
Nov 10th, 2007, 03:41 PM
thank you everyone for the suggests and explanations about it.
Best Regards!

penagate
Nov 10th, 2007, 04:14 PM
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.