expression
Regex::splitn: limit output fields
Produce at most the specified number of fields. The final field contains the unsplit remainder. This example uses the external regex crate; see the staged Cargo manifest. Expected stdout (not executed): ["key", "a:b"] Common mistake: Interpreting the limit as the maximum delimiter count.
Formal Syntax & Structure
rust syntaxrust
re.splitn(text, limit)Working Example
Example Snippetrust
fn main() { let re = regex::Regex::new(":").unwrap(); let parts: Vec<_> = re.splitn("key:a:b", 2).collect(); println!("{:?}", parts);}