AJAX - The Complete Reference

(avery) #1

PART IV


Appendix A: JavaScript Quick Reference 583


We summarize the important flags, repetition indicators, escape codes, and related
object properties of regular expressions in Tables A-21 through A-26.
Clearly, if you are not familiar with regular expressions just listing out their syntax is
not going to help much, so we direct readers to online tutorials or the companion book if
what is found here is more cryptic than useful.

Comments


JavaScript supports single-line C++ style comments:

// I am a comment!

as well as the standard C style multiline comment form:

/*
* I am a multiple line comment.
* Please use me in your code.
* Thank you!
*/

You may see XHTML comments within JavaScript blocks:

<script type="text/javascript">
<!--

//-->
</script>

Regular Expression Matches Does Not Match
/\Wten\W/ “ ten “ “ten”, “tents”
/\wten\w/ “aten1” “ ten”, “1ten “

/\bten\b/ “ten” “attention”, “tensile”,
“often”
/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/ “128.22.45.1” “abc.44.55.42”,
“128.22.45.”
/^(http|ftp|https):\/\/.*/ “https://www.w3c.org”,
“http://abc”

“file:///etc/motd”,
“https//www.w3c.org”

TABLE A-20 A Few Regular Expression Examples

Character Meaning

i Case-insensitive.
g Global match. Find all matches in the string, rather than just the first.
m Multiline matching.

TABLE A-21 Regular Expression Flags
Free download pdf