pub struct Regex { /* private fields */ }
Expand description
POSIX regular expression.
Implementations§
Source§impl Regex
impl Regex
Sourcepub fn new(pattern: &str, flags: CompFlags) -> Result<Regex, String>
pub fn new(pattern: &str, flags: CompFlags) -> Result<Regex, String>
Compiles pattern as a regular expression.
By default, pattern is assumed to be a basic regular expression. To interpret it as an
extended regular expression, add CompFlags::EXTENDED
to the flags
. See also other
CompFlags
values to control some other aspects of the regex.
§Returns
Compiled regex or an error message.
Sourcepub fn matches(
&self,
input: &str,
max_matches: usize,
flags: MatchFlags,
) -> Result<Vec<Match>, String>
pub fn matches( &self, input: &str, max_matches: usize, flags: MatchFlags, ) -> Result<Vec<Match>, String>
Matches input string against regex, looking for up to max_matches
matches.
Regexes can contain parenthesized subexpressions. This method will return up to
max_matches
-1 of those. First match is reserved for the text that the whole regex
matched.
flags
dictate how matching is performed. See MatchFlags
for details.
§Returns
Ok
with an empty vector if no match found, or ifmax_matches
is 0 and there were no errors.Ok
with a non-empty vector ifmax_matches
was non-zero and a match was found. First element of the vector is the text that regex as a whole matched. The rest of the elements are pieces of text that were matched by parenthesized subexpressions.Err
with an error message.
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
Mutably borrows from an owned value. Read more