Skip to content

[BUG]: Empty replacement strings are ignored in string replacement functions #16547

Closed

Description

@autistic-avenger

Description

When using replaceAfter, replaceAfterLast, replaceBefore, or replaceBeforeLast with an empty replacement string, I expect that matched portion to be replaced with "" hence removing that part of the string. Instead, each function returns the original string unchanged.

If this is indeed a bug I would love to work on this and open a PR?

Related Issues

No I couldn't find any

Questions

Is this expected or is there a design choice behind this ?

Demo

No response

Reproduction

replaceAfter( 'beep boop', ' ', '', 0 );
replaceAfterLast( 'beep boop baz', 'p', '', 13 );
replaceBefore( 'Hello World!', 'World', '', 0 );
replaceBeforeLast( 'beep boop baz', 'p', '', 13 );

Expected Results

beep 
beep boop
World!
p baz

Actual Results

beep boop
beep boop baz
Hello World!
beep boop baz

Version

0.4.1

Environments

Node.js

Browser Version

No response

Node.js / npm Version

No response

Platform

No response

Checklist

  • Read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.

Activity

  1. stdlib-bot commented on Nov 8, 2026

    @stdlib-bot
    Contributor

    👋 Hi there! 👋

    And thank you for opening your first issue! We will get back to you shortly. 🏃 💨

    If you have any further questions while waiting for a response, please join our Zulip community to chat with project maintainers and other community members.

  2. changed the title [-]Empty replacement strings are ignored in string replacement functions[/-] [+][BUG]: Empty replacement strings are ignored in string replacement functions[/+] on Nov 8, 2026
  3. added
    BugSomething isn't working.
    UtilitiesIssue or pull request concerning general utilities.
    on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working.UtilitiesIssue or pull request concerning general utilities.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions