View Full Version : regular expression help

10-26-2009, 09:19 AM
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])");

10-26-2009, 10:40 AM
May be email validation regular expression.

Try giving some random strings to it, and then checkout the result.

Philip M
10-26-2009, 11:08 AM
Not an email validator. Try experiments with this:-

<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");


I read it that str must contain at least 6 characters
and the first character must be a letter a-z or A-Z.
Remaining characters must be letters, digits, underscore or hyphen (and no others).
str must contain at least one uppercase letter 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! :eek:) $ . * ? and + see:-


Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems." Jamie Zawinski.