11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Table A-27: Some Regular Expression Examples<br />

Regular Expression Matches Does Not Match<br />

/\bten\b/ ten attention, tensile,<br />

often<br />

/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/ 128.22.45.1 abc.44.55.42,<br />

128.22.45.<br />

/^(http|ftp|https):\/\/.*/ https://www.w3c.org,http://abc file:///etc/motd,<br />

https//www.w3c.org<br />

We summarize the important flags, repetition indicators, escape codes, and related object<br />

properties of regular expressions in Tables A-28 through A-33. See Chapter 8 for a detailed<br />

discussion.<br />

Table A-28: Regular Expression Flags<br />

Character Meaning<br />

i Case-insensitive.<br />

g Global match. Find all matches in the string, rather than just the first.<br />

m Multiline matching.<br />

Table A-29: Regular Expression Repetition Quantifiers<br />

Character Meaning<br />

* Match previous item zero or more times<br />

+ Match previous item one time or more<br />

? Match previous item zero or one times<br />

{m, n} Match previous item at minimum m times, but no more than n times<br />

{m, } Match previous item m or more times<br />

{m} Match previous item exactly m times<br />

Table A-30: Regular Expression Character Classes<br />

Character Meaning<br />

[chars] Any one character indicated either explicitly or as a range between the<br />

brackets<br />

[^chars] Any one character not between the brackets represented explicitly or as a<br />

range<br />

. Any character except newline<br />

\w Any word character. Same as [a-zA-Z0-9_]<br />

\W Any non-word character. Same as [^a-zA-Z0-9_]<br />

\s Any whitespace character. Same as [ \t\n\r\f\v]<br />

\S Any non-whitespace character. Same as [^ \t\n\r\f\v]<br />

\d Any digit. Same as [0-9]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!