...

View Full Version : regular expression help



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

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

</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! :eek:) $ . * ? 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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum