Jump to content
Larry Ullman's Book Forums

Format Of End Of Regular Expressions


Recommended Posts

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

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

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...