Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: regex problem

  1. #1
    Regular Coder
    Join Date
    Dec 2007
    Posts
    269
    Thanks
    28
    Thanked 0 Times in 0 Posts

    regex problem

    does ^[a-zA-Z_]{3} match between a-z with 3 digit plus _

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    No it matches any string starting with three characters a-zA-Z_. So aBc is valid, but ab2 is not and a_c222 is valid. If its only supposed to be 3 characters in length, you need to add a $ at the end of you're pattern to bound it between start and end.
    Also, if you plan on adding digits to it, use the \w instead. A word is classified as any alphanumeric character plus the _.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Regular Coder
    Join Date
    Dec 2007
    Posts
    269
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    No it matches any string starting with three characters a-zA-Z_. So aBc is valid, but ab2 is not and a_c222 is valid. If its only supposed to be 3 characters in length, you need to add a $ at the end of you're pattern to bound it between start and end.
    Also, if you plan on adding digits to it, use the \w instead. A word is classified as any alphanumeric character plus the _.
    how can i do it with 3 digit between a and z

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    ^[a-z]{3}$
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Regular Coder
    Join Date
    Dec 2007
    Posts
    269
    Thanks
    28
    Thanked 0 Times in 0 Posts
    and _


  •  

    Posting Permissions

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