time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

repl.txt (959B)


      1 
      2 {{alias}}( str, search, newval )
      3     Replaces `search` occurrences with a replacement `string`.
      4 
      5     When provided a `string` as the `search` value, the function replaces *all*
      6     occurrences. To remove only the first match, use a regular expression.
      7 
      8     Parameters
      9     ----------
     10     str: string
     11         Input string.
     12 
     13     search: string|RegExp
     14         Search expression.
     15 
     16     newval: string|Function
     17         Replacement value or function.
     18 
     19     Returns
     20     -------
     21     out: string
     22         String containing replacement(s).
     23 
     24     Examples
     25     --------
     26     // Standard usage:
     27     > var out = {{alias}}( 'beep', 'e', 'o' )
     28     'boop'
     29 
     30     // Replacer function:
     31     > function replacer( match, p1 ) { return '/'+p1+'/'; };
     32     > var str = 'Oranges and lemons';
     33     > out = {{alias}}( str, /([^\s]+)/gi, replacer )
     34     '/Oranges/ /and/ /lemons/'
     35 
     36     // Replace only first match:
     37     > out = {{alias}}( 'beep', /e/, 'o' )
     38     'boep'
     39 
     40     See Also
     41     --------
     42