pub struct Regex { /* private fields */ }
Expand description
A Regex is the compiled version of a pattern.
Implementations§
source§impl Regex
impl Regex
sourcepub fn new(pattern: &str) -> Result<Regex, Error>
pub fn new(pattern: &str) -> Result<Regex, Error>
Construct a regex by parsing pattern
using the default flags.
An Error may be returned if the syntax is invalid.
Note that this is rather expensive; prefer to cache a Regex which is
intended to be used more than once.
sourcepub fn with_flags<F>(pattern: &str, flags: F) -> Result<Regex, Error>
pub fn with_flags<F>(pattern: &str, flags: F) -> Result<Regex, Error>
Construct a regex by parsing pattern
with flags
.
An Error may be returned if the syntax is invalid.
Note it is preferable to cache a Regex which is intended to be used more
than once, as the parse may be expensive. For example:
sourcepub fn from_unicode<I, F>(pattern: I, flags: F) -> Result<Regex, Error>
pub fn from_unicode<I, F>(pattern: I, flags: F) -> Result<Regex, Error>
Construct a regex by parsing pattern
with flags
, where
pattern
is an iterator of u32
Unicode codepoints.
An Error may be returned if the syntax is invalid.
This allows parsing regular expressions from exotic strings in
other encodings, such as UTF-16 or UTF-32.
sourcepub fn find_iter<'r, 't>(&'r self, text: &'t str) -> Matches<'r, 't>
pub fn find_iter<'r, 't>(&'r self, text: &'t str) -> Matches<'r, 't>
Searches text
, returning an iterator over non-overlapping matches.
Note that the resulting Iterator borrows both the regex 'r
and the
input string as 't
.
sourcepub fn find_from<'r, 't>(
&'r self,
text: &'t str,
start: usize,
) -> Matches<'r, 't>
pub fn find_from<'r, 't>( &'r self, text: &'t str, start: usize, ) -> Matches<'r, 't>
Returns an iterator for matches found in ‘text’ starting at byte index
start
. Note this may be different from passing a sliced text
in
the case of lookbehind assertions.
Example:
use regress::Regex;
let text = "xyxy";
let re = Regex::new(r"(?<=x)y").unwrap();
let t1 = re.find(&text[1..]).unwrap().range();
assert!(t1 == (2..3));
let t2 = re.find_from(text, 1).next().unwrap().range();
assert!(t2 == (1..2));
sourcepub fn find_ascii(&self, text: &str) -> Option<Match>
pub fn find_ascii(&self, text: &str) -> Option<Match>
Searches text
to find the first match.
The input text is expected to be ascii-only: only ASCII case-folding is
supported.
sourcepub fn find_iter_ascii<'r, 't>(&'r self, text: &'t str) -> AsciiMatches<'r, 't>
pub fn find_iter_ascii<'r, 't>(&'r self, text: &'t str) -> AsciiMatches<'r, 't>
Searches text
, returning an iterator over non-overlapping matches.
The input text is expected to be ascii-only: only ASCII case-folding is
supported.
sourcepub fn find_from_ascii<'r, 't>(
&'r self,
text: &'t str,
start: usize,
) -> AsciiMatches<'r, 't>
pub fn find_from_ascii<'r, 't>( &'r self, text: &'t str, start: usize, ) -> AsciiMatches<'r, 't>
Returns an iterator for matches found in ‘text’ starting at byte index
start
.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Regex
impl RefUnwindSafe for Regex
impl Send for Regex
impl Sync for Regex
impl Unpin for Regex
impl UnwindSafe for Regex
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)