Search
 
SCRIPT & CODE EXAMPLE
 

RUST

rust regex split

///	Note:
///	This section requires that this crate is compiled with the pattern
///	Cargo feature enabled, which requires nightly Rust.
///	
///	More information in the link below...
use regex::Regex; // 1.1.8

fn split_keep<'a>(r: &Regex, text: &'a str) -> Vec<&'a str> {
    let mut result = Vec::new();
    let mut last = 0;
    for (index, matched) in text.match_indices(r) {
        if last != index {
            result.push(&text[last..index]);
        }
        result.push(matched);
        last = index + matched.len();
    }
    if last < text.len() {
        result.push(&text[last..]);
    }
    result
}

fn main() {
    let seperator = Regex::new(r"([ ,.]+)").expect("Invalid regex");
    let splits = split_keep(&seperator, "this... is a, test");
    for split in splits {
        println!(""{}"", split);
    }
}
Comment

PREVIOUS NEXT
Code Example
Rust :: get the temp directory rust 
Rust :: transpose a matrix 
Rust :: where in Rust 
Rust :: string and str to string rust 
Rust :: rust lang underscore 
Rust :: armanriazi•rust•error•[E0106]: missing lifetime specifier -- src/main.rs:5:16 | 5 | fn dangle() - &String { | ^ expected named lifetime parameter 
Rust :: rust enter number from keyboard / stdin 
Rust :: control flow rust 
Rust :: Read a floating point number from stdin 
Rust :: rust comments 
Rust :: rust•armanriazi•error•value used here after move 
Rust :: armanriazi•rust•error•E0615•attempted to take value of method `collect` on type 
Rust :: how to get text from a file and store it in a variable rust 
Rust :: rust•armanriazi•error•[E0596]: cannot borrow `self.` as mutable, as it is behind a `&` reference 
Rust :: create a rust project Inside the folder 
Rust :: rust string split 
Lua :: repeating loop roblox 
Lua :: if part is touched 
Lua :: roblox tween color3 
Lua :: luau how to find something in table 
Lua :: for i = 1 to n roblox 
Lua :: roblox number between 1 and 10 
Lua :: get last characters of string lua 
Lua :: lua class 
Lua :: for loop in robox 
Lua :: roblox set color of text 
Lua :: lua add to table 
Matlab :: matlab if 
Matlab :: matlab stop running function 
Basic :: google sheets split column 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =