crates.io
...Test a match let b = regex_is_match!("[ab]+", "car"); assert_eq!(b, true); let b = bytes_regex_is_match!("[ab]+", b"car"); assert_eq!(b, true); See regex_is_match! Extract a value let f_word = regex_find!(r"\bf\w+\b", "The fox jumps."); assert_eq!(f_word...
Crate
v3.6.1
2026-07-29
github.com
## Summary
[summary]: #summary
Permit matching sub-slices and sub-arrays with the syntax `..`.
Binding a variable to the expression matched by a subslice pattern can be done
using syntax `<IDENT> @ ..` similar to the existing `<IDENT> @ <PAT>` syntax, for example:
```rust
// Binding a sub-array:
let [x, y @ .., z] = [1, 2...
RFC 2359
RFC
2018-03-08
~8 min read
blog.yoshuawuyts.com
Pattern Extensions— 2023-05-26
shapes of types
pattern initializers
pattern matching
pattern types
the "is" keyword
on product patterns
on string patterns
conclusion
Microsoft Build is happening this week, and with it come new announcements for
the C# language and dotnet runtime. I was watching the video: "What's...
Observations/Thoughts
2023-05-31
~12 min read
brave.com
...how many rules need to be checked without a match before a matching one is found
Complexity of a rule being evaluated, e.g. the more generic ones matching arbitrary patterns within a URL require more involved matching than a simple string search
Our previous algorithm relied on the observation...
News & Blog Posts
2019-07-02
~12 min read
github.com
## Summary
Allow macro expansion in patterns, i.e.
~~~ .rs
match x {
my_macro!() => 1,
_ => 2,
}
~~~
## Motivation
This is consistent with allowing macros in expressions etc. It's also a year-old [open issue](https://github.com/mozilla/rust/issues/6830).
I have [implemented](https://github.com/mozilla/rust/pull/14298...
RFC 85
RFC
2014-05-21
~1 min read
www.catmonad.xyz
Restructuring
Patterns
In Rust, there is this feature known as
“pattern matching”, whereby you can take apart a
piece of structured data by writing out patterns
which bind to parts of it. This process is known
as “destructuring”, because you’re breaking a
structure into parts.
But there’s this...
Observations/Thoughts
2023-04-12
~3 min read
seanmonstar.com
Pattern matching in Rust is, the first time it clicks, something magical.
When you define a domain subject with an enum, and then match on the various details, you can express logic in a very natural way, and reduce errors about forgetting to handle all the cases. It’s exceptional...
Rust Walkthroughs
2022-08-31
~7 min read
doc.rust-lang.org
...let reference = &4;
match reference {
// If `reference` is pattern matched against `&val`, it results
// in a comparison like:
// `&i32`
// `&val`
// ^ We see that if the matching `&`s are dropped, then the `i32`
// should be assigned to `val`.
&val => println!("Got a value via destructuring: {:?}", val),
}
// To avoid the `&`, you dereference...
Rust by Example
Book
2024-01-01
~1 min read
blog.logrocket.com
...rule1 | rule2 | rule3
Pest will first try to match rule1. If and only if rule1 fails, Pest will then try to match rule2 and so on. If the first rule matches, Pest will not attempt to match any other to find the best match.
Thus, when writing such alternatives, we...
Rust Walkthroughs
2023-02-08
~26 min read
registerspill.thorstenball.com
...The code is probably what many people would naturally do to implement a select_all_matches method: use the select_next_match in a loop until there’s no more matches to select. Voilà, all matches selected.When looking at it with Antonio, I knew this code as well as...
Rust Walkthroughs
2024-02-21
~4 min read
doc.rust-lang.org
Or patterns in macro-rules
Summary
• How patterns work in macro_rules macros changes slightly:
• $_:pat in macro_rules now matches usage of | too: e.g. A | B.
• The new $_:pat_param behaves like $_:pat did before; it does not match (top level) |.
• $_:pat_param is available in all editions...
The Rust Edition Guide
Book
2024-01-01
~2 min read
iximiuz.com
...MatchOp,
}
/// Parses a label matching operation.
///
/// ```
/// # use nom_parser_example::naive::{label_match, LabelMatch, MatchOp};
/// #
/// # fn main() {
/// assert_eq!(
/// label_match(r#"foo=="bar""#),
/// Ok(("", LabelMatch { label: "foo", value: "bar", op: MatchOp::Eql }))
/// );
/// assert_eq!(
/// label_match(r#"foo!~"2..""#),
/// Ok(("", LabelMatch { label: "foo", value: "2..", op: MatchOp::NeqRe }))
/// );
/// # }
/// ```
pub...
Rust Walkthroughs
2021-07-28
~15 min read
manishearth.github.io
...u8 = ...; // A_const
let A @ _ = ...; // A_let
match .. {
A => ...; // A_match
}
What happens here is that constants and variables occupy the same namespace. So A_let shadows
A_const here, and when we attempt to match, A_match is resolved to A_let and rejected (since
you can’t match...
News & Blog Posts
2018-04-17
~6 min read
github.com
## Summary
Rust currently forbids pattern guards on match arms with move-bound variables.
Allowing them would increase the applicability of pattern guards.
## Motivation
Currently, if you attempt to use guards on a match arm with a move-bound
variable, e.g.
```rust
struct A { a: Box<int> }
fn foo(n...
RFC 107
RFC
2014-06-05
~3 min read
doc.rust-lang.org
...macro_rules! example {
($e:expr) => { println!("first rule"); };
(const $e:expr) => { println!("second rule"); };
}
fn main() {
example!(const { 1 + 1 });
}
Here, in the 2021 Edition, the macro will match the second rule. If earlier editions had changed expr to match the newly introduced const expressions, then it would match the...
The Rust Edition Guide
Book
2024-01-01
~1 min read
github.com
...the existing `.contains()` method is incompatible with Needle API)
* `.find()`, `.rfind()`, `.find_range()`, `.rfind_range()`
* `.matches()`, `.matches_mut()`, `.rmatches()`, `.rmatches_mut()`
* `.match_indices()`, `.match_indices_mut()`, `.rmatch_indices()`, `.rmatch_indices_mut()`
* `.match_ranges()`, `.match_ranges_mut()`, `.rmatch_ranges()`, `.rmatch_ranges_mut()`
* `.trim_matches()`, `.trim_start_matches()`, `.trim_end_matches()`
* `.replace...
RFC 2500
RFC
2018-07-06
~41 min read
rust-leipzig.github.io
...Matches
Regarding the found matches I found some deviations. At first, the libraries oniguruma and tre do not support
Unicode category expressions like \p{Sm}. This expression matches all mathematical symbols like = or |.
The Rust regex crate matches additionally the symbol ∞.
Hyperscan returns more matches than other engines, e.g...
News & Blog Posts
2017-04-04
~7 min read
gaultier.github.io
...But not for match.
Alright, so after some searching around, I came up with this mouthful of a syntax:
Rust1 let value = match left.try_into() {
2 Ok(v) => v,
3 Err::<_, TryFromSliceError>(err) => {
4 // [...]
5 }
6 };
Which works! And the same syntax can be applied to the Ok branch...
Rust Walkthroughs
2025-02-12
~5 min read
adventures.michaelfbryan.com
...Matcher> Matcher for FallingEdge<M> {
fn matches_event(&mut self, event: &Event<'_>) -> bool {
let current_is_matched = self.inner.matches_event(event);
let is_falling_edge = self.previous_was_matched && !current_is_matched;
self.previous_was_matched = current_is_matched;
is_falling_edge
}
}
For convenience we can add a combinator...
News & Blog Posts
2020-02-11
~14 min read
beeb.li
...For each match, we see a couple of lines of context with line numbers above and below. The selected match is indicated
by a yellow chevron in the gutter. Each individual match can be toggled to be skipped during replacement
with s. The match appears in dimmed text if skipped...
Project/Tooling Updates
2026-05-20
~16 min read