easy-regex-0.7.4 has been yanked.
Usage
To force writing long regular expressions as readable as possible by making it verbose and clear to write/read, this lightweight crate has been created.
Introduction
It consists of few main methods and plenty of handy functions. You can write a long regex using them along with already-adjusted settings and prepared patterns for English, French, German, Persian, Chinese and Arabic languages.
Example 1 - Simple Regex
To create a regex like
r"(?i)(?-i:Don't capture)\s(me)";
one would use this crate as follows:
use ;
let text = "Don't capture ME"; // a text to be matched by our regex.
let result = insensitive
.group // SENSITIVE_NON_CAPTURE refers to
// (?i) and (?: ...) options which
// together makes the (?-i: ...) pattern.
.literal
.group;
let mut captured_text = result.clone.get_regex.unwrap
.captures.unwrap.get.unwrap.as_str;
assert_eq!;
assert_eq!; // insensitive ME
Example 2 - French Regex
There are a collection of useful regular expressions for other languages including French.
use ;
let text = "Adélaïde Aurélie";
let result = new_section.list;
let count = result.get_regex.unwrap.captures_iter.count;
assert_eq!;
Example 3 - Long Regex
And for a long one:
r"^(http|https|ftp):[/]{2}([a-zA-Z0-9-.]+\.[a-zA-Z]{2,4})(:[0-9]+)?/?([a-zA-Z0-9-._?,'/\\+&%$#=~]*)";
It would be:
use ;
let section_one = start_of_line
.group
.literal
.list;
let section_two = new_section
.list
.literal
.list
.into_group // put all previous patterns of "section_two" into a group with default options
// i.e. a capturing group like (previous patterns)
.group
.literal;
let section_three = new_section
.literal
.literal // special characters need not be scaped
// due to the next method, into_list.
.into_list
.into_group;
let collected_sections = format!;
let is_result_ok = new.build.is_ok;
assert_eq!;