The Rust regex crate states:
This crate provides a native implementation of regular expressions that is heavily based on RE2 both in syntax and in implementation. Notably, backreferences and arbitrary lookahead/lookbehind assertions are not provided.
As of this writing, "rust regex lookbehind" comes back with no results from DuckDuckGo.
I've never had to work around this before, but I can think of two approaches:
Approach 1 (forward)
- Iterate over
.captures()
for the pattern I want to use as lookbehind. - Match the thing I actually wanted to match between captures. (forward)
Approach 2 (reverse)
- Match the pattern I really want to match.
- For each match, look for the lookbehind pattern until the end byte of a previous capture or the beginning of the string.
Not only does this seem like a huge pain, it also seems like a lot of edge cases are going to trip me up. Is there a better way to go about this?
Example
Given a string like:
"Fish33-Tiger2Hyena4-"
I want to extract ["33-", "2", "4-"]
iff each one follows a string like "Fish"
.