String Patterns
This library makes it easier to validate and post-process strings in Rust. It builds on the Rust 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.
standard Rust with the Regex library
with the string-patterns library
standard Rust with the Regex library
with the string-patterns library
extract the third non-empty segment of a long path name
let path_string = "/var/www/mysite.com/web/uploads".to_string;
let domain = path_string.to_segment; // Some("mysite.com".to_string())
extract the first decimal value as an f64 from a longer string
let input_string = "Price £12.50 each".to_string;
let price_gbp = input_string.to_first_number; // 12.5 as f64
NB: Although I've used the library methods in three of my commercial projects, this library is very much an alpha release as I evaluate which of the many auxiliary methods, not documented here, belong in this library.