Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "string/replace/docs/types/index.d"

Index

Functions

Functions

repeat

  • repeat(str: string, search: string | RegExp, newval: string | Function): string
  • Replace search occurrences with a replacement string.

    Notes

    • 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 string

    new string containing replacement(s)

    Example

    var str = 'beep';
    var out = replace( str, 'e', 'o' );
    // returns 'boop'

    Example

    var str = 'Hello World';
    var out = replace( str, /world/i, 'Mr. President' );
    // returns 'Hello Mr. President'

    Example

    var capitalize = require( `@stdlib/string/capitalize` );
    
    var str = 'Oranges and lemons say the bells of St. Clement\'s';
    
    function replacer( match, p1 ) {
        return capitalize( p1 );
    }
    
    var out = replace( str, /([^\s]*)/gi, replacer);
    // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s'