#![doc = include_str!("../README.md")]
#![forbid(unsafe_code)]
#![warn(missing_docs)]
#![warn(rustdoc::broken_intra_doc_links)]
#![warn(rustdoc::bare_urls)]
#![cfg_attr(docsrs, feature(doc_cfg))]
pub mod charset;
pub mod error;
pub mod escape;
pub mod flags;
pub mod matcher;
pub mod unicode;
mod ast;
mod match_obj;
mod parser;
mod regex;
mod state;
pub use error::{Error, Result};
pub use escape::{escape, escape_literal_spaces, escape_special_only};
pub use flags::Flags;
pub use match_obj::{CaptureMatches, FindIter, GroupMatch, Match, MatchStatus, PartialMatch};
pub use regex::Regex;
pub fn new(pattern: &str) -> Result<Regex> {
Regex::new(pattern)
}
pub fn new_with_flags(pattern: &str, flags: Flags) -> Result<Regex> {
Regex::new_with_flags(pattern, flags)
}
pub fn is_match(pattern: &str, haystack: &str) -> bool {
match Regex::new(pattern) {
Ok(re) => re.is_match(haystack),
Err(_) => false,
}
}
pub fn find<'h>(pattern: &str, haystack: &'h str) -> Option<Match<'h>> {
Regex::new(pattern).ok()?.find(haystack)
}
pub fn find_all<'h>(pattern: &str, haystack: &'h str) -> Result<Vec<Match<'h>>> {
let re = Regex::new(pattern)?;
Ok(re.find_iter(haystack).collect())
}
pub fn replace(pattern: &str, haystack: &str, repl: &str) -> Result<String> {
let re = Regex::new(pattern)?;
Ok(re.replace(haystack, repl))
}
pub fn replace_all(pattern: &str, haystack: &str, repl: &str) -> Result<String> {
let re = Regex::new(pattern)?;
Ok(re.replace_all(haystack, repl))
}
pub fn split(pattern: &str, haystack: &str) -> Result<Vec<String>> {
let re = Regex::new(pattern)?;
Ok(re.split(haystack))
}