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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    regular expression help

    can anyone explain me in detail what this regular expression mean...
    each and every part of this sentence:
    var baseRegex = new RegExp("^(?=.{6,})(?=.*^[A-Za-z]([a-zA-Z0-9_-]+)$)(?=.*[A-Z])");

  • #2
    Regular Coder
    Join Date
    Dec 2007
    Posts
    107
    Thanks
    0
    Thanked 3 Times in 3 Posts
    May be email validation regular expression.

    Try giving some random strings to it, and then checkout the result.
    Programming & Webmaster Forum - AdSense Revenue Sharing forum

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    Not an email validator. Try experiments with this:-

    Code:
    <script type = "text/javascript">
    
    var str = "abcD99";
    if (/^(?=.{6,})(?=.*^[A-Za-z]([a-zA-Z0-9_-]+)$)(?=.*[A-Z])/.test(str)) {
    alert ("Match")
    }
    else {
    alert ("No Match");
    }
    
    </script>
    I read it that str must contain at least 6 characters
    ^(?=.{6,})
    and the first character must be a letter a-z or A-Z.
    (?=.*^[A-Za-z]
    Remaining characters must be letters, digits, underscore or hyphen (and no others).
    ([a-zA-Z0-9_-]+)$)
    str must contain at least one uppercase letter A-Z.
    (?=.*[A-Z])

    I have identified a bug in the above regex (six valid characters ending with an uppercase letter wrongly returns "No Match") :-
    (?=.*[A-Z]) should be (?=.*[A-Z]*)


    For more info which may help you disentangle curved brackets, square brackets and curly brackets (braces), and the meanings of the symbols ^ (which has two meanings depending on context! ) $ . * ? and + see:-

    http://www.w3schools.com/jsref/jsref_obj_regexp.asp#


    Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems." — Jamie Zawinski.
    Last edited by Philip M; 10-26-2009 at 11:51 AM. Reason: Typo


  •  

    Posting Permissions

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