Regular expression - starting and ending with a letter, accepting only letters, numbers and _
        Posted  
        
            by jreid9001
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by jreid9001
        
        
        
        Published on 2010-05-12T17:52:55Z
        Indexed on 
            2010/05/12
            17:54 UTC
        
        
        Read the original article
        Hit count: 203
        
regex
I'm trying to write a regular expression which specifies that text should start with a letter, every character should be a letter, number or underscore, there should not be 2 underscores in a row and it should end with a letter or number. At the moment, the only thing I have is ^[a-zA-Z]\w[a-zA-Z1-9_] but this doesn't seem to work properly since it only ever matches 3 characters, and allows repeated underscores. I also don't know how to specify requirements for the last character.
© Stack Overflow or respective owner