Skip to content

Matching ^ and $ with Regex::captures_at #1125

Answered by BurntSushi
ClementNerma asked this question in Q&A
Discussion options

You must be logged in to vote

I think the direct and most straight-forward answer to your specific question is regex.captures(&input[5..]).

Otherwise, if you want to start a search at an arbitrary position while taking look-behind assertions into account but want to limit your matches to those that start at the same position that you started your search, then you'll have to drop down to regex-automata and use its anchored option. The example there uses the PikeVM, but it will also work with the meta regex engine which is probably what you want to use. (The regex crate is itself just a wrapper around the meta regex engine.)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by BurntSushi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants