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