-
- <p>Following the header line and a comment, you see the job. Note that
- it uses <tt class="LITERAL">|</tt> as the delimiter instead of
- <tt class="LITERAL">/</tt>, because the pattern contains a forward
- slash, which would otherwise have to be escaped by a backslash
- (<tt class="LITERAL">\</tt>).</p>
-
- <p>Now, let's examine the pattern: it starts with the text <tt class=
- "LITERAL"><script.*</tt> enclosed in parentheses. Since the dot
- matches any character, and <tt class="LITERAL">*</tt> means:
- <span class="QUOTE">"Match an arbitrary number of the element left of
- myself"</span>, this matches <span class="QUOTE">"<script"</span>,
- followed by <span class="emphasis"><i class="EMPHASIS">any</i></span>
- text, i.e. it matches the whole page, from the start of the first
- <script> tag.</p>
-
- <p>That's more than we want, but the pattern continues: <tt class=
- "LITERAL">document\.referrer</tt> matches only the exact string
- <span class="QUOTE">"document.referrer"</span>. The dot needed to be
- <span class="emphasis"><i class="EMPHASIS">escaped</i></span>, i.e.
- preceded by a backslash, to take away its special meaning as a joker,
- and make it just a regular dot. So far, the meaning is: Match from the
- start of the first <script> tag in a the page, up to, and
- including, the text <span class="QUOTE">"document.referrer"</span>, if
- <span class="emphasis"><i class="EMPHASIS">both</i></span> are present
- in the page (and appear in that order).</p>
-
- <p>But there's still more pattern to go. The next element, again
- enclosed in parentheses, is <tt class="LITERAL">.*</script></tt>.
- You already know what <tt class="LITERAL">.*</tt> means, so the whole
- pattern translates to: Match from the start of the first <script>
- tag in a page to the end of the last <script> tag, provided that
- the text <span class="QUOTE">"document.referrer"</span> appears
- somewhere in between.</p>
-
- <p>This is still not the whole story, since we have ignored the options
- and the parentheses: The portions of the page matched by sub-patterns
- that are enclosed in parentheses, will be remembered and be available
- through the variables <tt class="LITERAL">$1, $2, ...</tt> in the
- substitute. The <tt class="LITERAL">U</tt> option switches to ungreedy
- matching, which means that the first <tt class="LITERAL">.*</tt> in the
- pattern will only <span class="QUOTE">"eat up"</span> all text in
- between <span class="QUOTE">"<script"</span> and the <span class=
- "emphasis"><i class="EMPHASIS">first</i></span> occurrence of
- <span class="QUOTE">"document.referrer"</span>, and that the second
- <tt class="LITERAL">.*</tt> will only span the text up to the
- <span class="emphasis"><i class="EMPHASIS">first</i></span>
- <span class="QUOTE">"</script>"</span> tag. Furthermore, the
- <tt class="LITERAL">s</tt> option says that the match may span multiple
- lines in the page, and the <tt class="LITERAL">g</tt> option again
- means that the substitution is global.</p>
-
- <p>So, to summarize, the pattern means: Match all scripts that contain
- the text <span class="QUOTE">"document.referrer"</span>. Remember the
- parts of the script from (and including) the start tag up to (and
- excluding) the string <span class="QUOTE">"document.referrer"</span> as
- <tt class="LITERAL">$1</tt>, and the part following that string, up to
- and including the closing tag, as <tt class="LITERAL">$2</tt>.</p>
-
- <p>Now the pattern is deciphered, but wasn't this about substituting
- things? So lets look at the substitute: <tt class="LITERAL">$1"Not Your
- Business!"$2</tt> is easy to read: The text remembered as <tt class=
- "LITERAL">$1</tt>, followed by <tt class="LITERAL">"Not Your
- Business!"</tt> (<span class="emphasis"><i class=
- "EMPHASIS">including</i></span> the quotation marks!), followed by the
- text remembered as <tt class="LITERAL">$2</tt>. This produces an exact
- copy of the original string, with the middle part (the <span class=
- "QUOTE">"document.referrer"</span>) replaced by <tt class=
- "LITERAL">"Not Your Business!"</tt>.</p>
-
- <p>The whole job now reads: Replace <span class=
- "QUOTE">"document.referrer"</span> by <tt class="LITERAL">"Not Your
- Business!"</tt> wherever it appears inside a <script> tag. Note
- that this job won't break JavaScript syntax, since both the original
- and the replacement are syntactically valid string objects. The script
- just won't have access to the referrer information anymore.</p>
-
- <p>We'll show you two other jobs from the JavaScript taming department,
- but this time only point out the constructs of special interest:</p>
-
+ <p>Following the header line and a comment, you see the job. Note that it uses <tt class="LITERAL">|</tt> as the
+ delimiter instead of <tt class="LITERAL">/</tt>, because the pattern contains a forward slash, which would
+ otherwise have to be escaped by a backslash (<tt class="LITERAL">\</tt>).</p>
+ <p>Now, let's examine the pattern: it starts with the text <tt class="LITERAL"><script.*</tt> enclosed in
+ parentheses. Since the dot matches any character, and <tt class="LITERAL">*</tt> means: <span class=
+ "QUOTE">"Match an arbitrary number of the element left of myself"</span>, this matches <span class=
+ "QUOTE">"<script"</span>, followed by <span class="emphasis"><i class="EMPHASIS">any</i></span> text, i.e. it
+ matches the whole page, from the start of the first <script> tag.</p>
+ <p>That's more than we want, but the pattern continues: <tt class="LITERAL">document\.referrer</tt> matches only
+ the exact string <span class="QUOTE">"document.referrer"</span>. The dot needed to be <span class=
+ "emphasis"><i class="EMPHASIS">escaped</i></span>, i.e. preceded by a backslash, to take away its special meaning
+ as a joker, and make it just a regular dot. So far, the meaning is: Match from the start of the first
+ <script> tag in a the page, up to, and including, the text <span class="QUOTE">"document.referrer"</span>,
+ if <span class="emphasis"><i class="EMPHASIS">both</i></span> are present in the page (and appear in that
+ order).</p>
+ <p>But there's still more pattern to go. The next element, again enclosed in parentheses, is <tt class=
+ "LITERAL">.*</script></tt>. You already know what <tt class="LITERAL">.*</tt> means, so the whole pattern
+ translates to: Match from the start of the first <script> tag in a page to the end of the last
+ <script> tag, provided that the text <span class="QUOTE">"document.referrer"</span> appears somewhere in
+ between.</p>
+ <p>This is still not the whole story, since we have ignored the options and the parentheses: The portions of the
+ page matched by sub-patterns that are enclosed in parentheses, will be remembered and be available through the
+ variables <tt class="LITERAL">$1, $2, ...</tt> in the substitute. The <tt class="LITERAL">U</tt> option switches
+ to ungreedy matching, which means that the first <tt class="LITERAL">.*</tt> in the pattern will only
+ <span class="QUOTE">"eat up"</span> all text in between <span class="QUOTE">"<script"</span> and the
+ <span class="emphasis"><i class="EMPHASIS">first</i></span> occurrence of <span class=
+ "QUOTE">"document.referrer"</span>, and that the second <tt class="LITERAL">.*</tt> will only span the text up to
+ the <span class="emphasis"><i class="EMPHASIS">first</i></span> <span class="QUOTE">"</script>"</span> tag.
+ Furthermore, the <tt class="LITERAL">s</tt> option says that the match may span multiple lines in the page, and
+ the <tt class="LITERAL">g</tt> option again means that the substitution is global.</p>
+ <p>So, to summarize, the pattern means: Match all scripts that contain the text <span class=
+ "QUOTE">"document.referrer"</span>. Remember the parts of the script from (and including) the start tag up to
+ (and excluding) the string <span class="QUOTE">"document.referrer"</span> as <tt class="LITERAL">$1</tt>, and the
+ part following that string, up to and including the closing tag, as <tt class="LITERAL">$2</tt>.</p>
+ <p>Now the pattern is deciphered, but wasn't this about substituting things? So lets look at the substitute:
+ <tt class="LITERAL">$1"Not Your Business!"$2</tt> is easy to read: The text remembered as <tt class=
+ "LITERAL">$1</tt>, followed by <tt class="LITERAL">"Not Your Business!"</tt> (<span class="emphasis"><i class=
+ "EMPHASIS">including</i></span> the quotation marks!), followed by the text remembered as <tt class=
+ "LITERAL">$2</tt>. This produces an exact copy of the original string, with the middle part (the <span class=
+ "QUOTE">"document.referrer"</span>) replaced by <tt class="LITERAL">"Not Your Business!"</tt>.</p>
+ <p>The whole job now reads: Replace <span class="QUOTE">"document.referrer"</span> by <tt class="LITERAL">"Not
+ Your Business!"</tt> wherever it appears inside a <script> tag. Note that this job won't break JavaScript
+ syntax, since both the original and the replacement are syntactically valid string objects. The script just won't
+ have access to the referrer information anymore.</p>
+ <p>We'll show you two other jobs from the JavaScript taming department, but this time only point out the
+ constructs of special interest:</p>