Warwick Posted May 26, 2012 Share Posted May 26, 2012 Hello everyone I see that regular expressions in the book usually end with /i e.g. '/^[A-Z0-9\'.-]{2,30}$/i' However, on page 86 under point 7, the i is left off after the end forward slash: '/^(\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*){6,20}$/' Why has the i been left off in this instance? Regards, Warwick Link to comment Share on other sites More sharing options...
margaux Posted May 26, 2012 Share Posted May 26, 2012 The i that you refer to makes the expression case-insensitive. Since the string is being used to verify a password, the match must be exact, hence the i is omitted. Link to comment Share on other sites More sharing options...
HartleySan Posted May 26, 2012 Share Posted May 26, 2012 Welcome to the forum, Warwick. The regex itself actually ends at the forward slash. The i after the forward slash is one of many possible modifiers that affects the entire regex. Specifically, the i meaning that the regex should search for strings in a case-insensitive fashion. The other common modifier you see for regexes is g, which is used for global searches (i.e., don't stop after the first match). While for JavaScript, the following link might shed some light on things: http://www.w3schools.com/jsref/jsref_obj_regexp.asp 1 Link to comment Share on other sites More sharing options...
Warwick Posted May 29, 2012 Author Share Posted May 29, 2012 Thanks very much for the quick replies! Warwick Link to comment Share on other sites More sharing options...
Recommended Posts