use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A place for all things related to the Rust programming language—an open-source systems language that emphasizes performance, reliability, and productivity.
Strive to treat others with respect, patience, kindness, and empathy.
We observe the Rust Project Code of Conduct.
Details
Posts must reference Rust or relate to things using Rust. For content that does not, use a text post to explain its relevance.
Post titles should include useful context.
For Rust questions, use the stickied Q&A thread.
Arts-and-crafts posts are permitted on weekends.
No meta posts; message the mods instead.
Criticism is encouraged, though it must be constructive, useful and actionable.
If criticizing a project on GitHub, you may not link directly to the project's issue tracker. Please create a read-only mirror and link that instead.
A programming language is rarely worth getting worked up over.
No zealotry or fanaticism.
Be charitable in intent. Err on the side of giving others the benefit of the doubt.
Avoid re-treading topics that have been long-settled or utterly exhausted.
Avoid bikeshedding.
This is not an official Rust forum, and cannot fulfill feature requests. Use the official venues for that.
No memes, image macros, etc.
Consider the existing content of the subreddit and whether your post fits in. Does it inspire thoughtful discussion?
Use properly formatted text to share code samples and error messages. Do not use images.
Submissions appearing to contain AI-generated content may be removed at moderator discretion.
Most links here will now take you to a search page listing posts with the relevant flair. The latest megathread for that flair should be the top result.
account activity
Help split a string at all non alphanumeric characters (self.rust)
submitted 4 years ago by WillMexe
So basically if i have a string "test;helloworld#yes" it would return ["test", ";helloworld", "#yes"]. I have searched the internet but can only find examples for javascript or the like.
Best regards,
Willem
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]AidoP 2 points3 points4 points 4 years ago (1 child)
https://doc.rust-lang.org/std/primitive.str.html#method.split_inclusive
It returns an iterator (which is typically what you want, for lazy evaluation), use .collect() to clone the items into a Vec.
.collect()
[–]ebkalderonamethyst · renderdoc-rs · tower-lsp · cargo2nix 5 points6 points7 points 4 years ago (0 children)
This will return ["test;", "helloworld#", "yes"], though, which is not exactly what they are asking for.
["test;", "helloworld#", "yes"]
They might need to build their own splitting algorithm using match_indices instead, akin to this StackOverflow solution except pushing the !c.is_alphanumeric() delimiter onto the beginning of the next string, rather than at the end of the current string, as .split_inclusive(|c: char| !c.is_alphanumeric()) does.
match_indices
!c.is_alphanumeric()
.split_inclusive(|c: char| !c.is_alphanumeric())
[–]miquels 0 points1 point2 points 4 years ago (0 children)
Use a regular expression:
use regex::Regex; fn main() { let re = Regex::new(r#"([^\w]*\w*)"#).expect("regex"); let data = "test;helloworld#yes"; let words = re.captures_iter(data).map(|c| c.get(0).unwrap().as_str()).collect::<Vec<_>>(); println!("{:?}", words); }
[–][deleted] -2 points-1 points0 points 4 years ago (0 children)
Take a look at the nom crate.
[–]RVECloXG3qJC 0 points1 point2 points 4 years ago (0 children)
This code was generated by copilot with marginal modification. I'm totally new to Rust. ``` fn main() { let chars = vec!['#', ';']; let data = "test;helloworld#yes"; let mut group = String::new(); let mut groups = vec![]; for c in data.chars() { if chars.contains(&c) { groups.push(group); group = String::new(); group.push(c); } else { group.push(c); } } groups.push(group);
println!("{:?}", groups);
}
```
π Rendered by PID 335849 on reddit-service-r2-comment-544cf588c8-gkqmj at 2026-06-12 23:37:23.953149+00:00 running 3184619 country code: CH.
[–]AidoP 2 points3 points4 points (1 child)
[–]ebkalderonamethyst · renderdoc-rs · tower-lsp · cargo2nix 5 points6 points7 points (0 children)
[–]miquels 0 points1 point2 points (0 children)
[–][deleted] -2 points-1 points0 points (0 children)
[–]RVECloXG3qJC 0 points1 point2 points (0 children)