time-to-botec/squiggle/node_modules/@stdlib/string/substring-after-last
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00
..
bin feat: add the node modules 2022-12-03 12:44:49 +00:00
docs feat: add the node modules 2022-12-03 12:44:49 +00:00
etc feat: add the node modules 2022-12-03 12:44:49 +00:00
lib feat: add the node modules 2022-12-03 12:44:49 +00:00
package.json feat: add the node modules 2022-12-03 12:44:49 +00:00
README.md feat: add the node modules 2022-12-03 12:44:49 +00:00

substringAfterLast

Return the part of a string after the last occurrence of a specified substring.

Usage

var substringAfterLast = require( '@stdlib/string/substring-after-last' );

substringAfterLast( str, search[, fromIndex] )

Returns the part of a string after the last occurrence of a specified substring.

var str = 'beep boop';
var out = substringAfterLast( str, 'b' );
// returns 'oop'

out = substringAfterLast( str, 'o' );
// returns 'p'

By default, the search starts at the end of the string and proceeds backwards to the beginning. To start the search at a specified index, specify an integer for the fromIndex argument.

var str = 'beep boop';
var out = substringAfterLast( str, 'b', 3 );
// returns 'eep boop'

Notes

  • If a substring is not present in a provided string, the function returns an empty string.
  • If provided an empty substring, the function returns an empty string.

Examples

var substringAfterLast = require( '@stdlib/string/substring-after-last' );

var str = 'To be, or not to be, that is the question.';
var out = substringAfterLast( str, ', ' );
// returns 'that is the question.'

out = substringAfterLast( str, 'to be' );
// returns ', that is the question.'

out = substringAfterLast( str, 'question.' );
// returns ''

out = substringAfterLast( str, 'xyz' );
// returns ''

out = substringAfterLast( str, '' );
// returns ''

CLI

Usage

Usage: substring-after-last [options] --search=<string> [<string>]

Options:

  -h,    --help                Print this message.
  -V,    --version             Print the package version.
         --search string       Search string.
         --from-index int      Index at which to start the search.
         --split sep           Delimiter for stdin data. Default: '/\\r?\\n/'.

Notes

  • If the split separator is a regular expression, ensure that the split option is either properly escaped or enclosed in quotes.

    # Not escaped...
    $ echo -n $'foo\nbar\nbaz' | substring-after-last --search a --split /\r?\n/
    
    # Escaped...
    $ echo -n $'foo\nbar\nbaz' | substring-after-last --search a --split /\\r?\\n/
    
  • The implementation ignores trailing delimiters.

Examples

$ substring-after-last abcdefg --search d
efg

To use as a standard stream,

$ echo -n $'bar\nbaz' | substring-after-last --search b
ar
az

By default, when used as a standard stream, the implementation assumes newline-delimited data. To specify an alternative delimiter, set the split option.

$ echo -n 'bar\tbaz' | substring-after-last --search b --split '\t'
ar
az

See Also