pub struct CachedJsRegex { /* private fields */ }Implementations§
Methods from Deref<Target = Regex>§
Sourcepub fn find_iter<'r, 't>(
&'r self,
text: &'t str,
) -> Matches<BacktrackExecutor<'r, Utf8Input<'t>>>
pub fn find_iter<'r, 't>( &'r self, text: &'t str, ) -> Matches<BacktrackExecutor<'r, Utf8Input<'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<BacktrackExecutor<'r, Utf8Input<'t>>>
pub fn find_from<'r, 't>( &'r self, text: &'t str, start: usize, ) -> Matches<BacktrackExecutor<'r, Utf8Input<'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,
) -> Matches<<BacktrackExecutor<'r, Utf8Input<'t>> as Executor<'r, 't>>::AsAscii>
pub fn find_iter_ascii<'r, 't>( &'r self, text: &'t str, ) -> Matches<<BacktrackExecutor<'r, Utf8Input<'t>> as Executor<'r, 't>>::AsAscii>
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,
) -> Matches<<BacktrackExecutor<'r, Utf8Input<'t>> as Executor<'r, 't>>::AsAscii>
pub fn find_from_ascii<'r, 't>( &'r self, text: &'t str, start: usize, ) -> Matches<<BacktrackExecutor<'r, Utf8Input<'t>> as Executor<'r, 't>>::AsAscii>
Returns an iterator for matches found in ‘text’ starting at byte index
start.
Sourcepub fn replace(&self, text: &str, replacement: &str) -> String
pub fn replace(&self, text: &str, replacement: &str) -> String
Replaces the first match of the regex in text with the replacement string.
The replacement string may contain capture group references in the form $1, $2, etc.,
where $1 refers to the first capture group, $2 to the second, and so on.
$0 refers to the entire match. Use $$ to insert a literal $.
If no match is found, the original text is returned unchanged.
§Examples
use regress::Regex;
let re = Regex::new(r"(\w+)\s+(\w+)").unwrap();
let result = re.replace("hello world", "$2 $1");
assert_eq!(result, "world hello");
let re = Regex::new(r"(\d{4})-(\d{2})-(\d{2})").unwrap();
let result = re.replace("2023-12-25", "$2/$3/$1");
assert_eq!(result, "12/25/2023");Sourcepub fn replace_all(&self, text: &str, replacement: &str) -> String
pub fn replace_all(&self, text: &str, replacement: &str) -> String
Replaces all matches of the regex in text with the replacement string.
The replacement string may contain capture group references in the form $1, $2, etc.,
where $1 refers to the first capture group, $2 to the second, and so on.
$0 refers to the entire match. Use $$ to insert a literal $.
§Examples
use regress::Regex;
let re = Regex::new(r"(\w+)\s+(\w+)").unwrap();
let result = re.replace_all("hello world foo bar", "$2-$1");
assert_eq!(result, "world-hello bar-foo");
let re = Regex::new(r"\b(\w)(\w+)").unwrap();
let result = re.replace_all("hello world", "$1.$2");
assert_eq!(result, "h.ello w.orld");Sourcepub fn replace_with<F>(&self, text: &str, replacement: F) -> String
pub fn replace_with<F>(&self, text: &str, replacement: F) -> String
Replaces the first match of the regex in text using a closure.
The closure receives a &Match and should return the replacement string.
This is useful for dynamic replacements that depend on the match details.
If no match is found, the original text is returned unchanged.
§Examples
use regress::Regex;
let re = Regex::new(r"\d+").unwrap();
let text = "Price: $123";
let result = re.replace_with(text, |m| {
let num: i32 = m.as_str(text).parse().unwrap();
format!("{}", num * 2)
});
assert_eq!(result, "Price: $246");Sourcepub fn replace_all_with<F>(&self, text: &str, replacement: F) -> String
pub fn replace_all_with<F>(&self, text: &str, replacement: F) -> String
Replaces all matches of the regex in text using a closure.
The closure receives a &Match and should return the replacement string.
This is useful for dynamic replacements that depend on the match details.
§Examples
use regress::Regex;
let re = Regex::new(r"\d+").unwrap();
let text = "Items: 5, 10, 15";
let result = re.replace_all_with(text, |m| {
let num: i32 = m.as_str(text).parse().unwrap();
format!("[{}]", num * 10)
});
assert_eq!(result, "Items: [50], [100], [150]");Trait Implementations§
Source§impl Clone for CachedJsRegex
impl Clone for CachedJsRegex
Source§fn clone(&self) -> CachedJsRegex
fn clone(&self) -> CachedJsRegex
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CachedJsRegex
impl Debug for CachedJsRegex
Source§impl Deref for CachedJsRegex
impl Deref for CachedJsRegex
Source§impl<'de> Deserialize<'de> for CachedJsRegex
impl<'de> Deserialize<'de> for CachedJsRegex
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for CachedJsRegex
impl RefUnwindSafe for CachedJsRegex
impl Send for CachedJsRegex
impl Sync for CachedJsRegex
impl Unpin for CachedJsRegex
impl UnwindSafe for CachedJsRegex
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§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.