Struct remake::Remake
[−]
[src]
pub struct Remake { /* fields omitted */ }
A remake expression, which can be compiled into a regex.
Methods
impl Remake
[src]
pub fn compile(src: &str) -> Result<Regex, Error>
[src]
Evaluate some remake source to produce a regular expression.
Example: A mostly-wrong URI validator
use remake::Remake; let web_uri_re = Remake::compile( r#" let scheme = /https?:/ . '//'; let auth = /[\w\.\-_]+/; let path = ('/' . /[\w\-_]+/)*; let query_body = (/[\w\.\-_?]/ | '/')*; let frag_body = cap query_body as frag; /^/ . scheme . auth . path . ('?' . query_body)? . ('#' . frag_body)? . /$/ "#, ).unwrap(); assert!(web_uri_re.is_match("https://www.rust-lang.org")); assert!(web_uri_re.is_match("https://github.com/ethanpailes/remake")); assert_eq!( web_uri_re .captures("https://tools.ietf.org/html/rfc3986#section-1.1.3") .unwrap() .name("frag") .unwrap() .as_str(), "section-1.1.3" );
Errors:
Calling compile
on some remake source might result in an
Error
.
pub fn new(src: String) -> Result<Remake, Error>
[src]
Construct a remake expression which can be evaluated at a later time.
To go directly from a remake expression to a Regex
,
see Remake::compile
.
Example:
let remake_expr = Remake::new(r" 'a literal' ".to_string())?;
Errors:
Calling new
on some remake source might result in a
Error::ParseError
.
pub fn eval(self) -> Result<Regex, Error>
[src]
Evaluate a remake expression.
Example:
let remake_expr = Remake::new(r" 'a [li[teral' ".to_string())?; let re = remake_expr.eval()?; assert!(re.is_match("a [li[teral"));
Errors:
Calling eval
on a remake expression might result in a
Error::RuntimeError
.