Results 1 to 6 of 6

Thread: Help with regular expression

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Italy
    Posts
    117

    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.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Help with regular expression

    What language are you using?

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Help with regular expression

    [a-zA-Z0-9\._]{4,17}

  4. #4
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    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.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Italy
    Posts
    117

    Re: Help with regular expression

    thank you everyone for the suggests and explanations about it.
    Best Regards!

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width