Results 1 to 5 of 5

Thread: Regex First Character Is Different Than

  1. #1
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default Regex First Character Is Different Than

    Hi, I've been trying for a long time to do this, but to no avail. I have a regex ,/[^!]([a-zA-Z0-9]{1,15})/, that sort of works, but not exactly. I would like to make sure the first character is not an exclamation point, but is a number/letter, sort of like /[!]{0}([a-zA-Z0-9]{1,15})/, which unfortunately doesn't work. Any help would be highly appreciated.
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Code:
    /^[A-z0-9]{1,15}$/
    must contain at least 1 character and have no more than 15 characters
    must only contain case-insensitive alphabet letters or digits

    the reason yours didn't work was because you checked for the non existence of the carot, however you didnt specify the beginning or the end of the string... by doing a carot at the beginning you are starting the string and a dollar sign at the end you are ending the string... so the only allowable input is what you are checking for...

    a carot symbol anywhere else but the first character of the expression means the following statement must NOT exist
    [^!]
    states the next character cannot be an exclamation point... however that could be confused with....
    next character is either a carot or an exclamation point,

    what you could have done was /^(^!) or /^^[!] the latter of which could also be confusing
    Last edited by boogyman; 05-15-2008 at 08:18 PM. Reason: added explanation

  3. #3
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    the problem with that is i am not matching it at the beginning of the string. e.g ";!ignore match;"
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  4. #4
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    does anyone know how to do this?
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  5. #5
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    how do you determine where to start??

    you have two options..
    1. you can put in some checks to do the first part, then check your "string"
    2. only pass in the part of the string that you wish to check against an exclamation point


    on a side note, if you dont want there to be an exclamation point anywhere in the entire string you can use

    Code:
    /(^!)/

Bookmarks

Posting Permissions

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