Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #13390

Re: Javascript Tutorial - Leave a comment regarding this online tutorial

Message-ID <2711826.zdxgZUoe2N@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2012-04-15 10:36 +0200
Subject Re: Javascript Tutorial - Leave a comment regarding this online tutorial
Newsgroups comp.lang.javascript
References <21708501.852.1334458849164.JavaMail.geo-discussion-forums@pbig5> <1399409.AFRqVoOGUt@PointedEars.de>
Followup-To comp.lang.javascript

Followups directed to: comp.lang.javascript

Show all headers | View raw


Thomas 'PointedEars' Lahn wrote:

> 5. Your definition of "word" is incorrect or your description of the
>    replace example is imprecise.
> 
>      text.replace(/him/gi,repText)
> 
>    will _return_ the value of `text' with all _case-insensitive_
>    _occurences_ (substrings) of "him" replaced by the value of `repText'.
>    (The string value of `text' will remain _unchanged_.  String values
>    are _immutable_ in ECMAScript implementations.)
> 
>    A word, on the other hand, is usually defined as a substring delimited
>    by the start of input (or line), the end of input (or line), and/or
>    non-word
>    characters (such as white-space).  Whereas a word character is usually
>    defined (and so by the `\w' and `\b' escape sequences in ECMAScript) to
>    include the alphanumeric ASCII characters and the `_' (underscore)
>    character (/\w/ ~ /[0-9A-Za-z_]/).  That is, the return value of
> 
>      "foobarbaz".replace(/bar/gi, "bla")
> 
>    is
> 
>      "fooblabaz"
> 
>    whereas "bar" surely cannot be considered a word in any sense, but a
>    _substring_ instead.

Which reminds me that you have neglected to mention

  - special substrings in the second string-value argument, such as "$&";
  - the (most useful) use of a Function instance reference (callback) as 
    second argument (what I have said above only applies to non-function
    values for that argument).  For example:

      /* "&#8709;&#322;&#8364;&#182;&#359;&#8592;&#8595;&#8594;&#960;" */
      "∅ł€¶ŧ←↓→π".replace(
        /./g,
        function (match) {
          return "&#" + match.charCodeAt(0) + ";";
        })

      /* "∅ł€¶ŧ←↓→π" */
      "&#8709;&#322;&#8364;&#182;&#359;&#8592;&#8595;&#8594;&#960;".replace(
        /&#(\d+);/g,
        function (match, paren1) {
          return String.fromCharCode(paren1);
        })


PointedEars
-- 
Sometimes, what you learn is wrong. If those wrong ideas are close to the 
root of the knowledge tree you build on a particular subject, pruning the 
bad branches can sometimes cause the whole tree to collapse.
  -- Mike Duffy in cljs, <news:Xns9FB6521286DB8invalidcom@94.75.214.39>

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Javascript Tutorial - Leave a comment regarding this online tutorial Javascript replace <arie3456@gmail.com> - 2012-04-14 20:00 -0700
  Re: Javascript Tutorial - Leave a comment regarding this online tutorial Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-15 10:19 +0200
    Re: Javascript Tutorial - Leave a comment regarding this online tutorial Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-15 10:36 +0200
      Re: Javascript Tutorial - Leave a comment regarding this online tutorial Javascript replace <arie3456@gmail.com> - 2012-04-15 02:11 -0700
    Re: Javascript Tutorial - Leave a comment regarding this online tutorial Javascript replace <arie3456@gmail.com> - 2012-04-15 02:27 -0700
      Re: Javascript Tutorial - Leave a comment regarding this online tutorial Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-15 11:44 +0200
    Re: Javascript Tutorial - Leave a comment regarding this online tutorial Dr J R Stockton <reply1216@merlyn.demon.co.uk.not.invalid> - 2012-04-16 20:10 +0100
  Re: Javascript Tutorial - Leave a comment regarding this online tutorial "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-04-15 15:39 +0000

csiph-web