String Patterns
This library makes it easier to validate and manipulate strings in Rust. It builds on Rust's standard library with help from the default regular expression library, regex. It has no other dependencies. It aims to make working with strings as easy in Rust as it is Javascript or Python without compromising performance. The library provides a number of utility methods to split strings into vectors of strings or a head and tail components and to extract valid numbers from longer texts. I will add more documentation as the library progresses beyond the alpha stage. I added variant match and replace methods with _ci (case-insensitive) or _cs (case-sensitive) suffixes as shorthand for the equivalent plain methods thatv require a boolean case_insensitive flag. In case-insensitive mode the non-capturing /(?i)/ flag is prepended automatically.
standard Rust with the Regex library
with the string-patterns library
standard Rust with the Regex library
with the string-patterns library
Replace text in a vector of strings
let sample_strings = .to_strings; /// cast to vector of owned strings
let pattern = r#"a([pr])"#;
let replacement = "æ$1";
let new_strings = sample_strings.pattern_replace;
/// should yield the strings "æpples", "bananas", "cærrots", "dates"
Replace multiple pattern/replacement pairs
let source_str = "The dying Edmund decides to try to save Lear and Cordelia.".to_string;
let pattern_replacements = ;
/// Should equal "The dying Edward decides to try to save Lear and Cecilia."
let target_str = source_str.pattern_replace_pairs;
Extract the third non-empty segment of a long path name
let path_string = "/var/www/mysite.com/web/uploads".to_string;
if let Some = path_string.to_segment
Extract the first decimal value as an f64 from a longer string
const GBP_TO_EUR = 0.83f64;
let input_string = "Price £12.50 each".to_string;
if let Ok = input_string.
NB: Although I've used the library methods in three of my commercial projects, this project is very much in its alpha stage as I evaluate which of the many auxiliary methods, not documented here, belong in this library. Version updates in the 0.1.x series reflect mainly corrections to this file.