Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce String::remove_matches to remove all matches of a pattern in a string. #50206

Closed
frewsxcv opened this issue Apr 25, 2018 · 1 comment · Fixed by #71780
Closed

Introduce String::remove_matches to remove all matches of a pattern in a string. #50206

frewsxcv opened this issue Apr 25, 2018 · 1 comment · Fixed by #71780
Assignees
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@frewsxcv
Copy link
Member

frewsxcv commented Apr 25, 2018

Like replace(..., ""), but doesn't result in any allocations.

I started implementing this in #50015 but got stuck, mainly because of limitations in the Pattern APIs.

let mut s = String::from("Trees are not green, the sky is not blue.");
s.remove_matches("not ");
assert_eq!("Trees are green, the sky is blue.", s);

This issue has been assigned to @jcotton42 via this comment.

@frewsxcv frewsxcv added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Apr 25, 2018
@XAMPPRocky XAMPPRocky added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Oct 2, 2018
@frewsxcv frewsxcv added C-feature-request Category: A feature request, i.e: not implemented / a PR. and removed C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Jan 1, 2019
@jcotton42
Copy link
Contributor

@rustbot claim

@rustbot rustbot self-assigned this Apr 26, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Mar 18, 2021
…joshtriplett

Implement String::remove_matches

Closes rust-lang#50206.

I lifted the function help from `@frewsxcv's` original PR (rust-lang#50015), hope they don't mind.

I'm also wondering whether it would be useful for `remove_matches` to collect up the removed substrings into a `Vec` and return them, right now they're just overwritten by the copy and lost.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Mar 18, 2021
…joshtriplett

Implement String::remove_matches

Closes rust-lang#50206.

I lifted the function help from ``@frewsxcv's`` original PR (rust-lang#50015), hope they don't mind.

I'm also wondering whether it would be useful for `remove_matches` to collect up the removed substrings into a `Vec` and return them, right now they're just overwritten by the copy and lost.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Mar 19, 2021
…joshtriplett

Implement String::remove_matches

Closes rust-lang#50206.

I lifted the function help from `@frewsxcv's` original PR (rust-lang#50015), hope they don't mind.

I'm also wondering whether it would be useful for `remove_matches` to collect up the removed substrings into a `Vec` and return them, right now they're just overwritten by the copy and lost.
@bors bors closed this as completed in eb95ace Mar 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants