Got more questions? Find advice on: ASP | SQL | XML | Windows
Welcome to RegexAdvice Sign in | Join | Help

Matching a limited character set with rules

  •  12-03-2008, 1:31 AM

    Matching a limited character set with rules

    I'm in need for a regular expression that will match a limited character set that has rules. 

    The rules are:

    1.  3 to 15 character long (inclusive) e.g. "abc" "abcdefghijklmno"
    2.  Only characters A-Z 0-9 - _ . ( ) [ ] e.g. thats A-Z 0-9, dash, underscore, period, left & right round bracket, and left & right square bracket. (No spaces allowed)
    3.  The string cannot start with anything other than A-Z or 0-9 e.g Match = "bob123[bob]" but not "[bob]bob123".
    4.  The string cannot contain two adjacent punctuation marks (punctuation is dash, underscore, period, left/right round bracket and left/right square bracket).


    So based on those, here a just a few examples of what the regular expression would match:

    • bob123[bob]
    • bob[123]BOB
    • 123(bob_HI
    • B12_b(0]b

    But it would not match:

    • [bob]123[bob]
    • (bob)123bob
    • .bob123
    • _bob123
    • bob{(123
    • b_{bob}123
    • bob@home
    • bob$ayshello

    Im developing this in C#.NET and I can get it to match the lenth and the A-Z 0-9 and special characters, however I do not know how to enforce the last two rules.

    Any help would be greatly appreciated.  Smile

     

     

View Complete Thread